Using Rhinoscript Macros renders GH unresponsive

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("-_Export\n\"" + savename + "\"\n _Enter\n _Enter")
  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? (6.1 KB)

Solved it; issue seems related to using the toggl button

What was the problem? Would you mind sharing the solution?

I just posted a similar problem here:

In my case the problem was with the press-Button while it works fine using the Toggle button (but Toggle unfortunately isn’t the proper activation type in my case…). < scratching head >.

// Rolf

I am not entirely sure what the problem was, but holding the “toggle boolean” button for a few moments seems to solve the issue. Your theory about “odd number of times” may very well be at the core of the issue.

I just realised I am actually using the “press button” just as you. This may call for further investigation.