Rhino 8 python script error opening Grasshopper

Hi all,

I have a simple python script that references the Grasshopper .dll in order to open a grasshopper file. It works in Rhino 7 and (I’m 98% sure) it was working in Rhino 8 until recently.

Now, when Rhino 8 runs the script, it opens the referenced file in Grasshopper but it does recognise bulit-in GH components like XY plane. Here is an example GH file that loads in Rhino 8 when loaded manually in Grasshopper but fails to load via the script.
CurveBoolean.gh (8.5 KB)
Here are the errors it displays when it loads via the script:


you can see for example, that none of the curve components have loaded:
image

Here is the script. Any help would be much appreciated - thanks!

#! python 2
import clr
import os
import Rhino
rv = major_version = int(str(Rhino.RhinoApp.Version).split('.')[0])
if rv == 7:
    clr.AddReferenceToFileAndPath(r"C:\Program Files\Rhino 7\Plug-ins\Grasshopper\Grasshopper.dll")
elif rv == 8:
    clr.AddReferenceToFileAndPath(r"C:\Program Files\Rhino 8\Plug-ins\Grasshopper\Grasshopper.dll")
    #Previously the Rhino 8 Fix to get it working
    #https://discourse.mcneel.com/t/system-uri-not-working/148206
    clr.AddReference("System.Runtime")
import Grasshopper as gh

print rv
gh_scriptinterface = gh.Plugin.GH_RhinoScriptInterface()
gh_scriptinterface.OpenDocument(r"C:\Users\mho\Downloads\CurveBoolean.gh")

Hi Michael. I’m not on a Rhino 8 laptop, so I can’t check, but maybe this method works instead:

Also, I don’t think one would need to explicitly reference the Grasshopper.dll. At least not in GHPython for at least a decade, but maybe things are different with the new script editor.

Edit: Just whipped out my work laptop, and those script do indeed appear to work in Rhino 8 SR11:

1 Like

Brilliant! Thanks Anders that did it :slight_smile:

1 Like

No worries, the new IronPython component appears to works as well, just for completeness:

240906_CloseDocument_00.gh (4.7 KB)
240906_OpenDocument_00.gh (5.3 KB)

See you soon at the Rhino Developer Meeting :partying_face:

1 Like