sadovshikov
(Vitaly Sadovshchikov)
August 10, 2022, 8:30am
1
Hi! I launch the same snippet of a code in the Rhino Python Editor and in the gh Python script editor component, for Rhino it works well whereas running it in Grasshopper it returns None. What I do wrong with gh
import rhinoscriptsyntax as rs
obj_id = rs.GetObject("Object", 8+16, True, True)
rh_obj = rs.coercerhinoobject(obj_id, True, True)
print rh_obj.Attributes
You need to change the scriptcontext when targeting the Rhino document from a GHPython script. See this post for a quick example:
Hi guys. If you want to fiddle with the Rhino document from GHPython, you must explicitly set the script context to target the Rhino document. Here’s one approach:
import Rhino as rc
import scriptcontext as sc
import rhinoscriptsyntax as rs
# Set context to Rhino document and disable redraw
sc.doc = rc.RhinoDoc.ActiveDoc
rs.EnableRedraw(False)
# Fiddle with the Rhino document
# Set context back to Grasshopper
rs.EnableRedraw(True)
sc.doc = ghdoc
1 Like