Automating Script Opening and Closing in Grasshopper Post Text:

Hello everyone, I’m seeking help with a Grasshopper challenge. I often work with many scripts and need to automate their opening and closing for efficiency in my design and analysis work.

The Challenge:

I’m looking to streamline this process by creating a Grasshopper Python script that performs the following tasks:

  1. Open Script: I want to provide a file path to the script, and when I run the Python script within Grasshopper, it should open the specified script file onto the current Grasshopper canvas. This would save me from manually navigating to the “File” menu, selecting “Open,” and finding the script in my folder each time.
  2. Close Script: After working with a script and wanting to move on to another, I’d like the ability to close the current script using a button to prevent accumulating numerous open Grasshopper tabs created by the first script.

if anyone knows how to accomplish either of these tasks, please share your knowledge.

I’ve not tried it from within Grasshopper itself, but from outside Grasshopper (from the command line shell, an external Python process, both into rhino runscript=, or within Rhino via Macros, Rhinoscript or Rhino Python) you can use Rhino commands, e.g.:
_grasshopper _editor _load _document _open _enterend

In the Grasshopper definition, you could have a GHPython script that closes the file that another Python script one just opened. Just connect that to a standard button, and only close the file if x == True:

Otherwise, why is a button better than an extra couple of clicks going to File → Close? Custom UI toolbars can be defined for Rhino, that will run any custom Command. But I’m not sure how to add custom UI elements in Grasshopper, other than plug-ins’ components.

1 Like

Something like this might work for you: (2.9 KB) (1.9 KB)


Thank you so much for your detailed response! this is exactly what I was looking for.

1 Like