Jump to content
kiryha

Filter node children's output with python

Recommended Posts

How to filter node.children() output so it will return nodes only of the specified type (vopsurface, for example)
Currently, I do it with a procedure:
 

def extractVop(listOfChildrens):
    for node in listOfChildrens:
        if node.type().name() == 'vopsurface':
            return node

But probably there is more elegant way like node.children().type('vopsurface')

Share this post


Link to post
Share on other sites

This is the proper way, I think. It is commonly used in $HH/python2.7libs to filter nodes by type: https://pastebin.com/EnmhzJKj

You can use list comprehensions to make it one-liner:

vops = [c for c in node.children() if c.type().name() == 'vopsurface']

 

Edited by f1480187
  • 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

×