RhinoApp.RunScript(script, true); not work

Hi I Change some c# plugins from RH 5 to Rh6

and one I only copy and it work

It has this in
RhinoApp.RunScript("-_Print _Setup _Destination _PageSize 209.926 296.926 _Enter _View _ViewportArea _Window 0,0 100,100 _Enter _Enter _Enter _Go", true);

but if I ceate a new Plug in
and use the same it not work.

the difference is only Rhino common
C:\Program Files (x86)\Rhinoceros 5.0\System\RhinoCommon.dll : work
C:\Program Files\Rhino WIP\System\rhinocommon.dll : work not

it is also with Insert Block
“_-Insert File=Yes LinkMode=Embed D:\Kalzip_Rhino_tools_6_0\Next_V\Block_s\Kon_Next_III.3dm Block 0,0,0 1.0 0.0”;
or it is possible to insert a file on a other way in c#?

Thanks Robert

Hi @Robert,

First, if you are scripting Rhino commands from your plug-in, make sure the command classes are decorated with Rhino.Commands.CommandStyle attribute.

Also, it is possible that the scripted versions of the Print and Insert commands have changed. You will want to run these commands manually to ensure your command script will work. Using the MacroEditor is a great way to test command scripts.

– Dale

Thanks Dale

it work

namespace KZunroll3
{[
Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)
]
but after I Need the ID of this Block in Rh 5 I du it with :

public static Guid Mycommand_id(string script, RhinoDoc doc)
{
Guid id;
Rhino.DocObjects.RhinoObject obj;

        RhinoApp.RunScript(script,true);
        obj = doc.Objects.First();
        id = obj.Id;
        return id;
    }

but this not work do you have a Idea ?

Hi @Robert,

This is not a good way of determining what objects a scripted command added or changed. Try using a function like this instead:

/// <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,
/// </returns>
public static Guid[] RunCommandScript(RhinoDoc doc, string script, bool echo)
{
  var rc = new Guid[0];
  try
  {
    var start_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber;
    RhinoApp.RunScript(script, false);
    var end_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber;
    if (start_sn < end_sn)
    {
      var object_ids = new List<Guid>();
      for (var sn = start_sn; sn < end_sn; sn++)
      {
        var obj = doc.Objects.Find(sn);
        if (null != obj)
          object_ids.Add(obj.Id);
      }
      rc = object_ids.Distinct().ToArray();
    }
  }
  catch
  {
    // ignored
  }
  return rc;
}

– Dale

Thanks Dal

it is very nice I get a list of id´s and the last is my Block

-Robert