Python blocks interface after running fine commands

Hello,

I have a python script running like a charm excepted that I do not recover any control on the canvas (GH window) afterwards. I have to quit and relaunch Rhino and GH.

------ First:

import rhinoscriptsyntax as rs
import scriptcontext as sc

------ Then, I am changing the scriptcontext using:

sc.doc = Rhino.RhinoDoc.ActiveDoc

------ I can then call commands:

rhino_line = sc.doc.Objects.Add(geometry, attributes)
rs.UnselectAllObjects()
rs.SelectObject(rhino_line)
rs.Command("-_Export " + filepath + filename + " " + settings, False)
rs.DeleteObject(rhino_line)

------ I then put back the original Grasshopper document as default using:

sc.doc = ghdoc

I got it working by playing with the order of those “sc.doc” commands. But it does not seem to work all the time and I do not see what I am doing wrong.
I tried in vain to add a timer after the writing of the file in case GH was not waiting for the system to store the file.

Thank you !!

It get control back 1 time over 2 when

sc.doc = ghdoc

is before

rs.Command("-_Export " + filepath + filename + " " + settings, False)

I need to trigger/activate with a Button my python code 2 times to get GH control back one time.

That’s likely a culprit (see this and this). Try either holding it down instead of just clicking it, or replacing it with a boolean toggle or a value list.

Thank you very much !!

1 Like