RhinoApp.RunScript does not work in C# using RhinoCommon 8.9.24194

Hi,

I have seen that there might have been some issues with RunScript recently, but I did not find a proper answer so I will ask here.

It is simple, RunScript in this case (code bellow) will not work and it will return false. I tried to set echo to true, but there is no difference. As you can see after it fails I write the importCommand in the prompt just so i can test it.

image

And when I copy and paste that command - it works…so the path is good and the entire command is good…but there is some problem with calling the RunScript from code. Any ideas? I did not use this for quite a while and have a vague recollection that “something” must be done so that the RunScript works…maybe change RunMode in the command? But I cannot remember… I also found some older code where this used to work, so I wonder if it is something related to Rhino 8.

I tried it with 3dm, dxf and dwg files…so it is not about the files themselves.

Thanks.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{  
    string importCommand = "_-Import \"C:\\Users\\milos\\Desktop\\30080-05_T03-OL.dxf\" _Enter";    
    bool importSuccess = RhinoApp.RunScript(importCommand, false);

    if (!importSuccess)
    {
        RhinoApp.WriteLine("Failed to import file");
        RhinoApp.WriteLine("Command history: " + RhinoApp.CommandHistoryWindowText);              
    }

    return Result.Success;
}

Hi @dimcic ,
I am not familiar with C#, but what happens if you first define your file path as a raw string with @:

string fileFullPath = @"C:\\Users\\milos\\Desktop\\30080-05_T03-OL.dxf";
string importCommand = string.Format("_-Import {0} _Enter", fileFullPath);
bool importSuccess = RhinoApp.RunScript(importCommand, false);

Hi djordje,
thanks but the formatting of the command is not the problem (i tried what you suggested as well, including couple of other formatting options)…just to test it I do:

RhinoApp.WriteLine(importCommand);

And then I can see this in Rhino Prompt:

_-Import C:\Users\milos\Desktop\30080-05_T03-OL.dxf _Enter

So I simply select that, copy and paste it and it works…the file gets imported. That is the proof that the importCommant is good, but that the RunScript fails.

Hi @dimcic ,
When you run the upper raw string code with @, how does the Rhino Command line look like? Some message must have appeared there (file not found or unable to open, …).

Hi @dimcic ,

Perhaps this?

string fileFullPath = "C:\\Users\\milos\\Desktop\\30080-05_T03-OL.dxf";
string importCommand = string.Format("_-Import \"{0}\" _Enter", fileFullPath);
bool importSuccess = RhinoApp.RunScript(importCommand, false);

Also, check out this:

– Dale

1 Like

Hi @dale

thanks. The formatting of the importCommand string did not matter…but when I said “…I have a vague recollection that “something” must be done so that the RunScript works…” it was that Attribute:

[Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)]

After I added that, it worked (with all types of string formatting)…so that is the solution.
Thanks.

1 Like