Jump to content
Sign in to follow this  
sanostol

Python::Finde all nodes of one type, all versions

Recommended Posts

Hello,

let's say I have a node called io::caching::2.1, where 2.1 is the version, and io is the namespace. but the scene has many nodes of this type, but with different versions, is there a way to get all the nodes with all versions, without looping over the complete scene?

thanks

Martin

Share this post


Link to post
Share on other sites

If your objects are just thrown all over the entire /obj root, then yes, you have to loop over all of them. But if you organize them into subnets you can loop over only the children of a subnet, or any object. Like all nodes inside a geo for instance.

In this example code I am filtering by .type() but you could alter the IF/THEN statement to examine the .name() instead.

def childrenOfNode(node, filter):
    # Return child nodes of type matching the filter (i.e. geo etc...).
    result = []
    if node != None:
        for n in node.children():
            t = str(n.type())
            if t != None:
                for filter_item in filter:
                    if (t.find(filter_item) != -1):
                        # Filter nodes based upon passed list of strings.
                        result.append('%s~%s' % (n.name(), t))                          # name~type.
                    result += childrenOfNode(n, filter)
    return result
    
nodes = childrenOfNode(hou.node("/obj/my_subnet/),["Object null"])                     # Fetch any null object nodes inside this subnet.

 

Edited by Atom

Share this post


Link to post
Share on other sites

The best way is to find the corresponding node types you want to search for and check for all instances of those types.  For example, if your node is a SOP:

key = ("io", "caching")

all_instances = []

for node_type in hou.sopNodeTypeCategory().nodeTypes().values():
    components = node_type.nameComponents()

    if components[1:3] == key:
    	all_instances.extend(node_type.instances())

 

  • Like 1

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
Sign in to follow this  

×