Been learning Python though automating some of the tasks we do in the office on the project I am on, and would like to give the tools to the rest of the team.
Worked how how to write a simple script for moving Geometry up and down the shift vector but if Esc is pressed part way though the process it runs to the end and returns an Error. I have read up on Event Handling/Checking if escape been pressed but can’t get it to notice this when I run the code.
Current Code is below I someone could give me some pointers.
import rhinoscriptsyntax as rs
import RhinoPython.Host as __host
#Shift Model from Acad Origin to Rhino Origin or visa versa.
acadOrigin = (5100,55370,0)
rhOrigin = (0,0,0)
#check for esc press
def escape_test( throw_exception=True, reset=False ):
"Tests to see if the user has pressed the escape key"
rc = __host.EscapePressed(reset)
if rc and throw_exception:
raise Exception('escape key pressed')
return rc
def moveMTC ():
objs = rs.GetObjects('Select Objects to Move',0,True,True)
strDir = rs.GetString('Select Direction','Import',['Import', 'Export'])
if strDir == 'Import': shiftVec = rs.VectorCreate(rhOrigin,acadOrigin)
else: shiftVec = rs.VectorCreate(acadOrigin,rhOrigin)
m_objs = rs.MoveObjects(objs,shiftVec)
rs.SelectObject(m_objs)
if m_objs: rs.ZoomSelected(None,True)
rs.UnselectObjects(m_objs)
if __name__=="__main__":
moveMTC()
Thanks Matt