I am currently looking for a way to execute the command “RunPythonScript” in Rhino. Instead of doing this manually, I want to do this inside of a GHPython-Component in my Grasshopper file since I want to do a parameters study and need to execute Python for many different Rhino-compositions.
I did not find a way to do this with Rhino.RhinoDoc.ActiveDoc so I am afraid that I would have to use Rhino Compute or WIP or similar approaches.
Any tips?
The end goal would be to iterate (with Brute Force from TT Toolbox) over every possible geometrical configuration (which is being generated in grasshopper) and run a python script in Rhino in order to make some calculations in a FE-software. The idea is that this occurs automatically every loop in a GHPython component which accesses the active rhino doc but I did not found a way to run a python script in Rhino from within a GHPython component.
I am aware of the script context, the problem is that I did not find a way to call the function “RunPythonScript” in Rhino from GHPython (with sc.doc = Rhino.RhinoDoc.ActiveDoc )
This looks nice, but I am looking for a solution in which I do not need to execute commands in Rhino itself. Since I did not find a solution which allows me to run Python Files in Rhino directly with scripting components in GHPython this would not help me.
Oh great!
For me it partially works if I input rs.Command(“_RunPythonScript path\to\script.py”)
but it only executes “_RunPythonScript” and ignores the path, since it opens my path to my stored scripts and does not execute the script I indicated in the GHPython component. Do you have a Idea what I could change so it does it automatically?
THANKS already!
But why don’t you just run the code from GHPython (edit: either by copy/pasting the code or importing the functions/classes you need)? There shouldn’t be a reason to add these hacky layers of indirection (i.e. calling RunPythonScript from GHPython).