sanostol Posted September 19, 2016 Share Posted September 19, 2016 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 Quote Link to comment Share on other sites More sharing options...
Atom Posted September 19, 2016 Share Posted September 19, 2016 (edited) 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 September 19, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
graham Posted September 19, 2016 Share Posted September 19, 2016 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()) 1 1 Quote Link to comment Share on other sites More sharing options...
sanostol Posted September 20, 2016 Author Share Posted September 20, 2016 thanks a lot, works great ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.