GH.RunHeadless() Doesn't Work?

Hello :wave:t4:,

I have a .gh script I want to open and run in the background without loading the GUI.
I’m aware of GrasshopperPlayer but that isn’t quite what I’m looking for here.

All inputs/outputs are handled outside of the gh canvas via Eto.Forms interactions and.

I thought the following RhinoScript code should work:

Option Explicit
Call Main()

Sub Main()
    Dim GH
    Set GH = Rhino.GetPlugInObject("Grasshopper")
    
    ' Disable the startup banner
    Call GH.DisableBanner()
    
    ' Open the Grasshopper document
    Call GH.OpenDocument("path_to_my_grasshopper_script_i_want_to_run")
End Sub

RunHeadless seems to do nothing and I don’t see any additional information on it in the SDK docs here:

https://mcneel.github.io/grasshopper-api-docs/api/grasshopper/html/M_Grasshopper_Plugin_GH_RhinoScriptInterface_RunHeadless.htm

A workaround is closing the window after it’s loaded like so:

Option Explicit
Call Main()
Sub Main()
	Dim GH
	Set GH = Rhino.GetPlugInObject("Grasshopper")
    
	' Disable the startup banner
	Call GH.DisableBanner()
	
	' Open the Grasshopper document
	Call GH.OpenDocument("path_to_my_grasshopper_script_i_want_to_run")

	' Hide the editor
	Call GH.HideEditor()

End Sub

Or like this:

Option Explicit
Call Main()
Sub Main()
	Dim GH
	Set GH = Rhino.GetPlugInObject("Grasshopper")
    
	' Disable the startup banner
	Call GH.DisableBanner()
	
	' Run Grasshopper Headless
	Call GH.RunHeadless()

	' Open the Grasshopper document
	Call GH.OpenDocument("path_to_my_grasshopper_script_i_want_to_run")
    
	' Ensure Grasshopper starts minimized (or hidden)
    'If GH.IsEditorLoaded() Then
        'Call Rhino.Command("NoEcho ! _-Grasshopper _Window _Hide _EnterEnd", False)
	'End If
End Sub

But I would much prefer to never see the GUI at all.

Any ideas how to achieve that or is there something I’m doing wrong with RunHeadless?

Thank you all! :pray:t4:

RunHeadless is an internal function really only intended for grasshopper running in Rhino.Compute.

1 Like

@michaelvollrath you might like to check out this thread:

I worked out a work flow that allows a GH file with custom UI to be complied with the Rhino Script Compiler and launched headless via some hoop jumping in a Python launch script.

Cheers

DK

2 Likes

Understood, thanks @stevebaer. So, in summary, if I want to run Rhino,GH, or both headless ( and locally) I should be using Rhino.Compute to achieve that?

Thanks for your help!

Interesting thanks for sharing and for sharing each step as you tried things through your process! Looks like you did manage to get a headless implementation running via Python I’ll dig a bit more into and see if it’s viable for my needs.

Cheers! @kiteboardshaper

@michaelvollrath thanks mate. You can also check out this thread to see my latest product to use this workflow:

If you are on Rhino 8 you can download a demo from the package manager, just search for KaroroCAM.

Cheers

DK

1 Like

No, I was just pointing out that the RunHeadless function wasn’t intended to be called for any other purpose. Kiteboardshaper probably has a good technique for doing what you are after

1 Like

Oh okay, thank you @stevebaer !