I buildup a simple example in grasshopper, user can input a radius and then grasshopper can create a sphere by this raduis. Now I want to use another code (ex. python program) to launch this 3dm and gh file, change the radius by this python code and re-run the grasshopper. Is it possible?
My original intention is to create many parameterized models through grasshopper. The process can not lauch Rhino & grasshopper manually, the process has to be done through code program (ex. Python). Please give me any advice.
Thanks.
I believe the method officially supported by McNeel is to use Rhino Inside, which launches a headless version of Rhino, and controls it, from an exernal Python.
Whether using Rhino Inside or otherwise, the task is much easier, if the code that will run within Rhino or Grasshopper is adjusted, so that it will also accept the input radius from somewhere other than the same flashy GUI we human users would use.
I think environment variables are great for passing simple data in. I’ve used a local udp client/server too, to pipe logger messages from Python code within Rhino back to the command line, but that’s overkill for a single parameter.
I wrote a Python helper library, Cheetah-GH, that will run Grasshopper from the command line. I use it for parametric testing. It’s rough and ready, and I’ve not tried this out yet, but internally it uses an env variable to get the Python code within Rhino to tell Rhino to shutdown. It will also set each pair of extra command line args, as name/values of environment variables for the Rhino process it launches. Python code within Rhino can easily read their value with os.getenv.