Jump to content

Python - run function on node selection change


Recommended Posts

Hey guys, I was wondering if anyone new of a simple way to run a function when I select a different node?
I've currently got a little UI with pyQt and I've gotten to it to update using the ChildSelectionChanged node callbackEvent but that is only for specific networks. The only thing I can come up with is I have the script check for new sub networks everytime it runs and creates new callbacks for them. Surely there is a more efficient less dirty way to do this? 

 

Doing it the dirty way this is what i'm using when running the script, updating it per change on selection and when calling the close event: Only works with networks one down from obj but I imagine if I made this find all sub children it will have a performance impact?
 

def callBacks(self, enable):
	nodes = hou.node('/obj/').children()
	for node in nodes:
		if enable:
			if len(node.eventCallbacks()) == 0:
				node.addEventCallback((hou.nodeEventType.ChildSelectionChanged,), self.updateUI)
		else:
			node.removeAllEventCallbacks()

 

Edited by shadowst17
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...