添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
旅途中的鼠标垫  ·  7125messi的博客·  3 天前    · 
憨厚的大脸猫  ·  python ...·  3 天前    · 
霸气的花卷  ·  python list 错位相减 ...·  3 天前    · 
帅气的领带  ·  【Pyspark ...·  昨天    · 
不拘小节的牛排  ·  SCITEPRESS - SCIENCE ...·  1 月前    · 
成熟的香烟  ·  亚马逊Kindle ...·  3 月前    · 

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:
image834×211 14.4 KB

After launching Grasshopper manually:
image700×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")