Skip to content

Houdini: lsattr maybe use Houdini's own nodesearch #569

@BigRoy

Description

@BigRoy

What happened?

The Houdini lsattrs logic does a search for nodes based on a parameter name and value which is used for host.ls() in Houdini.

I just heard of nodesearch that comes with Houdini out of the box. It might be worth actually relying on that logic instead.

It could make lsattrs basically like this:

# pseudocode match any of {attr: value} in attrs
import hou
import nodesearch

def lsattrs(attrs):
    root = hou.node("/obj")
    for attr, value in attrs.items():
        matcher = nodesearch.RawParm(attr, value, exact=True)
        for node in matcher.nodes(root, recursive=True)
            yield node

And I noticed the current logic in Houdini doesn't actually ensure all input values of the attrs dict get matched but if we do actually want that:

# pseudocode match all of {attr: value} in attrs
import hou
import nodesearch

def lsattrs(attrs):
    root = hou.node("/obj")
    matchers = []
    for attr, value in attrs.items():
        matchers.append(nodesearch.RawParm(attr, value, exact=True))
    for node in nodesearch.Group(matchers, intersect=True):
        yield node

It could be worth investigating whether the logic used by nodesearch is faster or not.

Additional Context

This could be a micro-optimization so might only really be worth if host.ls() really becomes problematic. But leaving it here for future reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions