Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Rhino
- import Grasshopper as gh
- import clr
- clr.AddReferenceToFile("KangarooSolver.dll")
- import KangarooSolver as ks
- from System import Array
- import subprocess
- class Interrupter(ks.GoalObject):
- def __init__(self, on_id):
- self.PPos = Array.CreateInstance(Rhino.Geometry.Point3d, 0)
- self.on_id = on_id
- self.cmd = None
- def Calculate(self, p):
- if self.cmd is None: # no window - open one
- self.cmd = subprocess.Popen(["cmd.exe", "/c", "echo Press any key to interrupt & pause>nul"])
- if self.cmd.poll() is not None: # window was triggered (closed)
- for obj in ghenv.Component.OnPingDocument().Objects:
- if type(obj) == gh.Kernel.Special.GH_BooleanToggle and str(obj.InstanceGuid) in self.on_id:
- obj.Value = 0
- obj.ExpireSolution(True)
- raise KeyboardInterrupt("User requested interrupt")
- def Terminate(self): # close window
- if self.cmd is not None:
- self.cmd.terminate()
- # find guid of 'On' bool
- on_id = []
- for input in ghenv.Component.Params.Input:
- if input.NickName == "On":
- for s in input.Sources:
- attr = s.Attributes
- component = attr.GetTopLevel.DocObject
- on_id.append(str(component.InstanceGuid))
- try: # clean up unwanted window from previous instance
- interrupter.Terminate()
- except NameError: # instance doesn't exist yet
- pass
- interrupter = Interrupter(on_id)
- I = interrupter # roundabout variable naming because gh will reset I each time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement