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

1 Like

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.

6 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:

1 Like

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)

1 Like

@rcmcdougle :

The “-_Grasshopper” command has a “Window” option (not sure when it was added), and you can set it to “_Hide”.

I tried this macro in a Rhino button :

-_Grasshopper _Banner _Disable _Document _Open “/.gh”
-_Grasshopper _Window _Hide _Enter

Note : I have to run the command twice because somehow, when you open a file, it will always show the GH Window, so you need to apply this option after opening the file (silly, but hey, at least it works).
No more C# component that forces you to disable the solver before opening your GH file when you want to edit it.

Now it does kind of work, except somehow, while the Human UI is responsive, the Grasshopper definition doesn’t accept any input untill I call the GH window back…

This is really frustrating, I hope there will be a better integration in V7…

YES it is frustrating. Human UI gets us so close to a great tool for distribution of complex .gh files. I really wish there were a way to see just the UI and have Grasshopper do it’s job.

3 Likes

I want to add that this Windows/Focus problem between Rhino and GH also prevents from using a 3D mouse in GH.

Paning and zooming in large canvas would greatly benefit from this type of devices.

thank you very cool button

dear @marcsyp,

with the new Rhino version, there are news if is possible to open a Grasshopper file containing a script with Human UI through Rhino, but to activate only the Human UI Control Window, without opening the Grasshopper canvas, so that no one can look inside the file and to be able to change/edit something?

Thanks and best regards

Hello All,

If anyone is looking for a solution to this in 2022, with the release of Rhino 7 and the Grasshopper play function…

You can create a button with the following command:
!_-GrasshopperPlayer “C:*file location of grasshopper playdoc.gh*”

Remove the asterixis when pasting the file location.
the minus symbol “-” is important before the “GrasshopperPlay” as it stops the file explorer window from opening up.

3 Likes

Hi,
i tested the command !_-grasshopperplayer for a button with Rhino 7 r28 and in general it is a really interesting feature. I was running three different gh Scripts with Human UI components, including the gh script from rcmcdougle mentioned in the thread. The Human UI scripts were loaded, but when i wanted to close the launched window by clicking on the “x”, rhino is hanging and then crashes. A RhinoDotNetCrash.txt is generated. Here are the first lines:

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
*** bei HumanUI.Components.UI_Main.LaunchWindow_Component.SetupWin()***
*** bei System.EventHandler.Invoke(Object sender, EventArgs e)***
*** bei System.Windows.Window.OnClosed(EventArgs e)***
*** bei System.Windows.Window.WmDestroy()***

Somebody else running in this issue?

1 Like

Hi all. Late to the party here.

I do try to create a custom button to launch a Grasshopper definition by pressing a button using this command: -_Grasshopper _Document _Open "C:\path_to_my_file.gh" and it is opening the file but in the same time I do get stuck into command-line where I am asked:

Grasshopper option(Window Document Solver Banner).

How I can bypass this question automatically? Using Rhino7 r34 here.