Help understanding the use of RunScript in plugin context

Hi,

As a learning exercise I’m attempting to turn some of the scripted tools that my company have developed into a plugin (in C#). One of the tools we have for dimensioning our drawings makes use of Rhino’s built in ‘Offset’ command to get the user to select where they want a particular offset to go. I’ve managed to get it to run in the plugin (as a scriptrunner) however the issue I’m running into is retrieving the created offset curve. Is there good and/or supported way to do this if at all possible? My current understanding is that there isn’t.

RhinoApp.RunScript(“_Offset Cap=None InCPlane=Yes T”, false);

New to C#/plugin development so any help or suggestions will be appreciated :slight_smile:

Hi @Liam_Phillips,

This is from the Rhino SDK samples. Perhaps using a function like this is helpful.

/// <summary>
/// Runs a Rhino command script.
/// </summary>
/// <param name="doc">The active document.</param>
/// <param name="script">The script to run.</param>
/// <param name="echo">Echo prompts to the command window.</param>
/// <returns>
/// The identifiers of the objects that were most recently created or changed
/// by the scripted command. Retreive this objects using ObjectTable.FindId.
/// </returns>
public static Guid[] RunCommandScript(RhinoDoc doc, string script, bool echo)
{
  Guid[] rc = Array.Empty<Guid>();
  try
  {
    uint start_sn = RhinoObject.NextRuntimeSerialNumber;
    RhinoApp.RunScript(script, echo);
    uint end_sn = RhinoObject.NextRuntimeSerialNumber;
    if (start_sn < end_sn)
    {
      List<Guid> object_ids = new List<Guid>();
      for (uint sn = start_sn; sn < end_sn; sn++)
      {
        RhinoObject obj = doc.Objects.Find(sn);
        if (null != obj)
          object_ids.Add(obj.Id);
      }
      rc = object_ids.Distinct().ToArray();
    }
  }
  catch
  {
    // ignored
  }
  return rc;
}

– Dale

2 Likes

Great, thanks

Looks like the issue was that I was using:

doc.RuntimeSerialNumber;

instead of

RhinoObject.NextRuntimeSerialNumber;