I am trying to use the following code to bake geometry into Rhino, export an .stl and then delete the geometry immediately.
#inputs: geometries, filename, run, dir, index
import rhinoscriptsyntax as rs
print filename
name = filename.replace(".3dm",".stl")
savename = dir + '\\' + str(int(index)) + name
print savename
print ghdoc
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
if run:
for i in range(len(geometries)):
geo = geometries[i]
print geo
sc.doc = ghdoc
#we obtain the reference in the Rhino doc
doc_object = rs.coercerhinoobject(geo)
print doc_object
attributes = doc_object.Attributes
geometry = doc_object.Geometry
#we change the scriptcontext
sc.doc = Rhino.RhinoDoc.ActiveDoc
#we add both the geometry and the attributes to the Rhino doc
rhino_geo = sc.doc.Objects.Add(geometry, attributes)
#we put back the original Grasshopper document as default
sc.doc = ghdoc
rs.Command("-SelAll")
rs.Command("-_Export\n\"" + savename + "\"\n _Enter\n _Enter")
rs.Command("-SelAll")
rs.Command("-_Delete\n _Enter\n _Enter")
However, when I run this, the GH window becomes semi-unresponsive. I can still pan around and click toggle buttons, for instance, but I can’t move the GH components or perform most actions.
I’ll assume I am doing something wrong when performing the macros, but what?
test.gh (6.1 KB)