Jump to content

function order of execution


freaq

Recommended Posts

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...