Send a command from Grasshopper to Rhino in C#

In Grasshopper, it’s possible to send commands directly from Grasshopper to Rhino. How? By using the C# component.

Simply add the following line to your C# code.

Rhino.RhinoApp.RunScript(string script, bool echo);
//script: The command to send
//echo: Set to true for the command to appear in Rhino's command prompt

For example, if I want to automatically save the Rhino document, I could add the following to a C# component:

Rhino.RhinoApp.RunScript("Save", true);

For more complex commands, we can use some special syntax. For example, if I want to save the file with a custom filename, I can use:

Rhino.RhinoApp.RunScript("_-Save test3.3dm", true);

The hyphen allows us to modify parameters, and the underscore allows us to enter more than one command at once without Rhino waiting for manual user input.

More information

The full list of Rhino commands is available here.

For more detail about using the RunScript method, read this.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.