Hi Diana,
I have tried several different approaches using Rhinocommon to force the closing of compiled/GH Player ran Grasshopper script that uses a HumanUI or similar user interface.
None have worked.
As it is built right now GH scripts running in GH Player can either be:
-
Single Pass - using context aware inputs. These run once and exit and are not suitable for use with a HumanUI or similar user interface
-
Stay Alive - clicking ‘Keep open after command completes’ - these offer the use of a HumanUI or similar user interface and act like first class plugins - your user has no idea/no access to the GH file running the code. However the ONLY way to stop these scripts is to close Rhino.
I have asked the McNeel Developers for help in this regard, a simple to call a command like “rs.CloseGHplayer” sort of thing that would allow the developer clean control over the finishing up/closing of their script. Unfortunately no one has been able to offer a solution or even suggest that it might be looked at some point in the future.
Best I can offer for your command above is to use a custom preview component and with a stream filter. Have the stream filter tied to the HumanUI window status and you cut off the geometry preview when your user closes the control window.
McNeel Devs - using Grasshopper to develop GUI driven commands and even full on plugins is an ACTUAL THING. I personally have THREE commercial products built this way, and many other people are moving down the same path. Can we PLEASE have a clean way to terminate the running of our code??
Cheers
DK