Pass arguments to python script called from C# plugin

Dear community,

To load and run PYTHON scripts from C#.
I already found the RunPythonScript command, and was able to run a standalone script with filename “externalscript” from C# like:

        if (!Rhino.RhinoApp.RunScript("-RunPythonScript " + externalScript, echoScriptCommand))
           MessageBox.Show("ERROR: Loadscript FAILED!", "ModelSeatPanel", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

My questions:

  1. how can I pass arguments to this script (coming from my C# environment)?
  2. what is still in the engine/interpreter after running a script? Is it possible e.g. when clicking a button to run a function from a script, have the results like in global variables or somewhere else and then click another button to run another script that uses these variables?

Kind regards,


1 Like

On C#, just add your parameters after python script filename.

string macro = string.Format("_-RunPythonScript \"{0}\" \"{1}\" ", pyScript, dxf);
rhino.RunScript(macro, 1);

On Python, just rs.GetString(). It depends on parameter data type.

def myMain():
    myoptions = ["DXF"]
    FilePath = rs.GetString("Get DXF File", "DXF", myoptions)