Jump to content

FORCE A RETURN OUT OF A PYTHON NODE


DougStruthers

Recommended Posts

There are many different ways to do it in Python and HOM. You can wrap into a function and use returns in the body. Or raise descriptive errors and treat them differently. HOM has all sorts of custom errors too.

This one will cook a node without errors. Depending on the input, it may show a warning and stop the script from executing further:

node = hou.pwd()
geo = node.geometry()
pts = geo.iterPoints()

if not pts:
    raise hou.NodeWarning('Input geometry has no points.')

geo.addAttrib(hou.attribType.Global, 'number_of_points', len(pts))

 

Edited by f1480187
  • Like 1
Link to comment
Share on other sites

the easy solution is to wrap the entire node of the sop in a function, like f1 already suggested

def myfunction():
	print "print this"
	return
	print "but not this"

myfunction() #make sure you actually run your code at the bottom of course

 

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...