How to create a button in Rhino that launches a specific Human UI/GH script

I would prefer this to happen such that the user never sees Grasshopper? I would click the button in Rhino -> perform the operations in the UI -> Bake -> then close. Grasshopper is hidden with no opportunity for modification of the GH.

TIA
Robb

There is no simple and straightforward way to do this, but a collection of tricks make it possible. I think @marcsyp is the world expert on this - he may have some suggestions. Here’s the basic approach:

  1. Associate a button with a command macro that launches your grasshopper file. something like this:
    -_Grasshopper _Document _Open "C:/PathToYourGHfile.gh"
  2. to launch Human UI, just leave the “Launch Window” component’s run input set to true - and set the window to be “Child of Rhino” so it remains while grasshopper is minimized
  3. use a c# script inside your grasshopper script to minimize the GH window (only way I know of to hide GH window without making it inactive) Grasshopper.Instances.DocumentEditor.WindowState = FormWindowState.Minimized;
  4. if you want to close grasshopper after you’re done, you can trigger something like the following with c# script with a boolean input called “close”:
    if(close) Grasshopper.Instances.DocumentEditor.ScriptAccess_CloseAllDocuments();

like i said - not ideal. but possible to get a reasonable approximation of what you’re after.

3 Likes

This sounds like what I am after. Many thanks Andrew.

I did not know you could combine command macro and c# script under 1 button. I have familiarity with Python but no c# experience. Could you provide an example of what that full button would contain please?

It is a great privilege to have access to the knowledge and experience of those behind the tools. The Rhino community never ceases to amaze me.

Robb

Unfortunately that’s not what I’m saying; in the above points the C# scripts are executed in grasshopper, and the macro is just to launch a grasshopper script. I don’t believe there’s a way to trigger c# scripts with a button short of writing a full rhino plugin. The command macro for the button is merely what I have written:
-_Grasshopper _Document _Open "C:/PathToYourGHfile.gh"

and the grasshopper script contains c# scripts which execute on launch or when triggered by the user.

Create a button and execute a python file that can open GH, hide the window and assign data to a component. You can see the reference commands for this here: RhinoScript's Grasshopper Methods List?
All these commands are part of the Rhinoscriptsyntax, so will work as rs.AssignDataToParameters.

All you need to do is set up your GH file, find out the id for the GH toggle button that will switch on the window (if needed) and then hide the window.

You can also create a Rhino Button that executes the load function for Grasshopper without using the command line, using the Grasshopper.Instances.Load() without using the Show() method. Then you load the appropriate file using the DocumentEditor. This will load the GH script and document context without actually showing the GH window. Yay! HumanUI is finally grown up and can leave the parents house for greener pastures.

This requires building a rhino plugin with a button, as I understand it, and is supported in v6, at least that’s what the McNeel guys told me last week – plan on implementing it in the near future, will report back.

Marc

1 Like

It would be great if you could post the full code you would put under a Rhino button. It should also close the GH session when the UI Window is closed.

TIA
Robb

Anything new on this? I appreciate that this may be a low priority, but it would be a huge contribution to what I’m attempting and I would guess many others as well.

TIA ~ Robb

1 Like

Hi.
I’m also interested in this topic.

Still working on getting a super clean solution – but in the meantime, if you’re happy with an interim solution, you can see the code I’ve posted in this thread, which can be copy pasted into a new Rhino Command project in Visual Studio and adapted to your purpose:

I have been working on this again and find that creating the Rhino button to launch a given Grasshopper document is straightforward. BUT with my c# ignorance, I have not been able to steal / modify existing c# code to make this happen. I munged together the appropriate code to close the document but I haven’t succeeded with c# to open the session minimized or close Grasshopper when done. I would greatly appreciate your modifications to the attached file to accomplish these goals.

UI-ManageWindow-3.gh (15.4 KB)