Open / Save / Export from RhinoApp.RunScript in Rhinocommon

nope, tbh I hadn’t, just reread it now and pasted. it works. the difference is the double \ slashes?

So i have to write code to edit my path string to double every slash to be able to open the file?

Path.GetFullPath(path).Replace(@"", @"\");

Ill give that a swing later today.

well, ill be a monkeys uncle, it worked.

@menno apologies for not looking at it in detail!

Hi Chris,

I’m trying to understand the problem you are having scripting the Open command, as this works in Rhino for Windows (for me):

// Literal
string filename = "C:\\Projects\\Robie House\\Floorplan.3dm";
string script = string.Format("_-Open \"{0}\"", filename);
RhinoApp.RunScript(script, false);

As does this:

// Verbatim
string filename = @"C:\Projects\Robie House\Floorplan.3dm";
string script = string.Format("_-Open \"{0}\"", filename);
RhinoApp.RunScript(script, false);

Note in each example the filename is eventually surrounded by double-quote characters. This is an important step, as some file path strings contain spaces.

Of course, to script any Rhino command from a plug-in, your command class must be decorated with the CommandStyle(Style.ScriptRunner) attribute. But it looks like you already know this.

– Dale

Thanks. Yes. Ive followed all examples I could find but no result. Adding the extra slash cured it. Stumped if I know why though. However. Its solved now.

If there is something youd like me to test let me know. Im using rhinocommon 5 from the website and running latest rhino5 release candidate.

No worries, apology accepted :smile:

1 Like

Hi @ChristopherBotha this is my core, you cant try it:

namespace Import
{
  //you must have this
  [
  System.Runtime.InteropServices.Guid("81cfa536-5e0e-47e5-9665-f644c237e362"),
  Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)
  ] 

  public class ImportCommand : Command
  {
      public ImportCommand()
      {
          Instance = this;
      }
      public static ImportCommand Instance
      {
          get;
          private set;
      }
      public override string EnglishName
      {
          get { return "Import"; }
      }
      protected override Result RunCommand(RhinoDoc doc, RunMode mode)
      {
         string filename = @"D:\\temp\\test.3dm";
         RhinoApp.RunScript(String.Format("_-Import {0}", filename), false);
         return Result.Success;
      }
   }
}

Hi everyone! I was calling a method(contains export run code) from the script runner command. But caller command was not defined as script runner and I faced the exact error which @ChristopherBotha explained. So If you call the export containing method from another command be sure that the caller command is defined as script runner too.