freaq Posted February 12, 2013 Share Posted February 12, 2013 Hi guys, I'm new to python and I am trying to make a tool that allows me to create a curve to run a procedure on, and I want to draw this curve on top of existing geometry. this I turn on primitive snapping, and other primitives. the only issue is as the end of the script I want to turn the settings back to their original settings, this works fine with a box for example but not with the curve as I stay inside the toolstate. the snaping is therefore turned of before I create all the points for my curve. is there a way I can execute it later? I tired to put the code in two functions, executing the second function after the first one was complete, but still it is executed before. all help is appreciated. here is my code: #------------------- # start of code #------------------- # Get the scene viewer and snapping options snap = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.SceneViewer) # find whether primitive snapping is on. text = snap.snappingMode() text2 = snap.isSnappingToOtherObjects() #turn on prim snapping snap.setSnappingMode(hou.snappingMode.Prim) snap.setSnapToOtherObjects(1) #-------------------------- # the actual script for shooting the curves #-------------------------- def createcurve(): import toolutils import soptoolutils activepane = toolutils.activePane(kwargs) if activepane.type() == hou.paneTabType.SceneViewer: # Get the current context. sceneviewer = toolutils.sceneViewer() # Create a SOP container. container = soptoolutils.createSopNodeContainer(sceneviewer, "wire_") # Create the curve. newnode = soptoolutils.createSopNodeGenerator(container, "curve", None) # Turn on the highlight flag so we see the SOPs selected output. newnode.setHighlightFlag(True) if sceneviewer.isCreateInContext(): newnode.setCurrent(True, True) sceneviewer.enterCurrentNodeState() toolutils.homeToSelectionNetworkEditorsFor(newnode) else: container.setCurrent(True, True) toolutils.homeToSelectionNetworkEditorsFor(container) activepane.setPwd(container.parent()) activepane.setCurrentState("objcurve") elif activepane.type() == hou.paneTabType.NetworkEditor: soptoolutils.genericTool(kwargs, "curve") else: raise hou.Error("Can't run the tool in the selected pane.") def cleanup(): #-------------------------- # reset the snapping options #-------------------------- #reset snap mode snap.setSnapToOtherObjects(text2) snap.setSnappingMode(text) createcurve() cleanup() #---------------------- # end of code #---------------------- Best regards, Freek Hoekstra Quote Link to comment Share on other sites More sharing options...
edward Posted February 13, 2013 Share Posted February 13, 2013 I think setCurrentState() will cause your tool to effectively finish. So any clean up should be done prior to that, and probably prior to running genericTool() as well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.