Run a python3 script in Rhino8 from a custom C# plugin?

I’ve built a custom Rhino8 plugin in C#. I want one of the buttons in my plugin to execute the command -_RunPythonScript <my-script>.py` where the python script is a Python3 script. After sleuthing the internet a bit and consulting ChatGPT, I think the solution should be for the button to trigger this command

RhinoApp.Runscript("-_RunPythonScript <my-script>.py", true)

which should be equivalent to running that line in the Rhino command line. However, upon executing this line, I get the error message

Command: -RunPythonScript
Unknown command: -RunPythonScript

I am a bit stuck and wondering why the RunPythonScript is not recognized by RhinoCommon.

Somewhat tangentially related, but this seems to be a similar thread telling me that executing Python from the C# interface is still under development ( Executing Python 3 Script in C# ).

Hi @itsgallon,

Please review:

Any help?

– Dale

2 Likes

If the click sequence with the regular GUI to run your script in whichever Rhino’s Pythons is carried out, the corresponding Rhino Commands can be copy and pasted from the command history window.

Thank you, Dale. The line I was missing was the annotation

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

above the initial definition of the Rhino command. That is, in an abbreviated sense, writing it as

[CommandStyle(Style.ScriptRunner)]
public class myCustomCommand : Command

Now the plugin command can execute Rhino commands as expected.