Automating Grasshopper Geometry Creation with Python (and Hops

Hello everyone,

I am working on a geometric optimization problem where the geometries are generated using Grasshopper. I am currently trying to automate the geometry creation process by modifying parameter values in Grasshopper through a Python script. I have identified two approaches, but I am facing issues and would appreciate any guidance.

Approach 1: Running a Python Script Within Rhino

My first approach involves opening a Rhino file with a normal python script and then executing a Python script inside Rhino. This second script is intended to:

  • Open a Grasshopper file linked to the Rhino model openned (.3dm)
  • Modify variable values within the Grasshopper file using the -grasshopperplayer command. The values for these variables are read from a JSON or CSV file generated in parallel.
  • Execute Rhino commands that may or may not be linked to Grasshopper.

Issue with Approach 1

After opening the Grasshopper file using the Python script executed in Rhino, I am unable to run further Rhino commands because the command bar becomes “blocked”. Specifically, I encounter the following situation at the end of my Python script runned in Rhino :

Etat fin de script

It seems that once the script is executed, Rhino command bar gets stuck and does not allow further commands.

Approach 2: Using Hops

I also considered using the Hops plugin to establish a connection between my external Python program and Grasshopper. However, I have found limited documentation on how to achieve this for my specific use case. As I was trying to execute Python code in Rhino using the package ghhops_server I encontered several errors regarding the import of this package. Do you have any insights on this ?

Would anyone have insights on how to properly manage these issues? Any guidance on using Hops effectively or unblocking Rhino’s command bar after running a script would be greatly appreciated. Feel free to recommand any other method

Thanks in advance for your help!

Best regards,
Etienne