Jump to content

counting nodes


Recommended Posts

Hello everyone

I have a lot of nodes in my scene. I'd like to somehow know how many nodes there are that have a name following a particular format. 

So my nodes are named, "char0", "char1", "char2", ....... ,"char?"

Is there a way I can write an expression to count up these nodes?

In the example picture the expression should return 4. In practice, I have many more nodes, but the naming convention is consistent.

Thanks for any ideas!

node count.jpg

Link to comment
Share on other sites

You can count all nodes on object level by a specific name using Python.

# INPUT
node = hou.node("/obj")
search = hou.ui.readInput("Find OBJ nodes by name:", buttons=('Search',), title="Count nodes")
name = str(search[-1])

# SEARCH
obj_nodes = []
for child in node.children():
    obj_nodes.extend([child.name()])
match = [x for x in obj_nodes if name in x]
count = str(len(match))

# OUTPUT
print(match, count)
text = count + " nodes found named " + name + "."
hou.ui.displayMessage(text, buttons=('OK',), title="Number of nodes")

 

Edited by konstantin magnus
  • Like 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...