Hi all,
My Rhino Python Editor can no longer import the Grasshopper module.
I wrote a little script (script A) that opens grasshopper files from Python.
import rhinoscriptsyntax as rs
import Grasshopper as gh
import os
docName = rs.DocumentName()
docPath = rs.DocumentPath()
ghPath = docPath + docName[:docName.rfind(".")] + ".gh"
if os.path.exists(ghPath):
print "Opening associated GH file ", ghPath
gh_scriptinterface = gh.Plugin.GH_RhinoScriptInterface()
gh_scriptinterface.OpenDocument(ghPath)
It was working just fine until, I tried to run script A from a subprocess while opening a 3DM file, something like the below (script B)
callScript = '"{0}" "{2}" /nosplash /runscript="{1}"'.format(rhinoPath, scriptCall, fileName)
subprocess.call(callScript)
Now my Rhino python editor cannot import Grasshopper at all. I get the following error message:
I restarted my computer and the issue persists. ‘import Grasshopper’ was working perfectly fine until I tried to launch script A from another subprocess, now it is unrecognized.
How do I fix this?
Thanks @AndersDeleuran that helps me narrow it down.
Maybe I just don’t understand when I can ‘import Grasshopper’
‘import Grasshopper’ is successful after I manually launch Grasshopper in Rhino, but the import fails if I call it before
Before launching Grasshopper manually:
image 834×211 14.4 KB
After launching Grasshopper manually:
image 700×176 7.78 KB
Is there a way to reference the Grasshopper module before / without launching Grasshopper manually from Rhino?
Michael_H:
Is there a way to reference the Grasshopper module before / without launching Grasshopper manually from Rhino?
Yes you could manually reference the assembly if it is not already. Something like this:
import clr
clr.AddReferenceToFileAndPath(r"C:\Program Files\Rhino 7\Plug-ins\Grasshopper\Grasshopper.dll")