Jump to content

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


sanostol

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

Link to comment
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
Link to comment
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
  • Thanks 1
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...