Problem calling Rhinoscript from inside C# method


Dear community,

I am a starting C# developer and Rhinoceros user. I have used Rhinoscript and am now making my first attempts to work with C# and Rhinoceros.

I used code from called SampleCsModalForm, which I could compile and install. After installation, I could call the command SampleCsModalForm from within Rhinoceros and see a window with three buttons appear. When clicking one of the buttons, a MessageBox is called, which also works fine.

However, I also wanted to execute a script in the method that is called when a button is clicked:

private void HelloButton_Click(object sender, EventArgs e)
MessageBox.Show(“Hello Rhino!”, “SampleCsForm”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (Rhino.RhinoApp.RunScript("_-Line 0,0,0 10,10,10", true))
MessageBox.Show(“Runscript OK!”, “SampleCsForm”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
MessageBox.Show(“Runscript FAILED!”, “SampleCsForm”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

I expected a line to appear in Rhino, but I got as result the MessageBox saying Runscript FAILED! Any ideas what I did wrong? Also, my goal I am working towards is to call a rather big script from an rvb file instead of calling direct rhino commands, something like Loadscript (and execute it), but from within a C# method.

Kind regards,

Filip Rooms

(Menno Deij - van Rijswijk) #2

The command that shows the form should have CommandStyle equal to Style.ScriptRunner to be able to run scripts.

  public class SampleCsModalFormCommand : Command
    public SampleCsModalFormCommand()


Dear menno,

Thanks for your answer. I also just found where it says I can only run scripts like you say. Moving the call to the script to a method derived from the right parent class and adding [CommandStyle(Style.ScriptRunner)] indeed did the trick.

I also could run an external script using Rhino.RhinoApp.RunScript("_-LoadScript " + externalScriptNameAndPath, true)

(Menno Deij - van Rijswijk) #4

Great :smile: