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)


Edited by shadowst17

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now