mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
handle permissions and root more gracefully
This commit is contained in:
parent
816eb71393
commit
390c6d15a5
1 changed files with 23 additions and 10 deletions
|
|
@ -403,33 +403,46 @@ def imprint(node, data):
|
|||
node.setParmTemplateGroup(parm_group)
|
||||
|
||||
|
||||
def lsattr(attr, value=None):
|
||||
def lsattr(attr, value=None, root="/"):
|
||||
"""Return nodes that have `attr`
|
||||
When `value` is not None it will only return nodes matching that value
|
||||
for the given attribute.
|
||||
Args:
|
||||
attr (str): Name of the attribute (hou.Parm)
|
||||
value (object, Optional): The value to compare the attribute too.
|
||||
When the default None is provided the value check is skipped.
|
||||
root (str): The root path in Houdini to search in.
|
||||
Returns:
|
||||
list: Matching nodes that have attribute with value.
|
||||
"""
|
||||
if value is None:
|
||||
nodes = list(hou.node("/obj").allNodes())
|
||||
nodes += list(hou.node("/stage").allNodes())
|
||||
# Use allSubChildren() as allNodes() errors on nodes without
|
||||
# permission to enter without a means to continue of querying
|
||||
# the rest
|
||||
nodes = hou.node(root).allSubChildren()
|
||||
return [n for n in nodes if n.parm(attr)]
|
||||
return lsattrs({attr: value})
|
||||
|
||||
|
||||
def lsattrs(attrs):
|
||||
def lsattrs(attrs, root="/"):
|
||||
"""Return nodes matching `key` and `value`
|
||||
|
||||
Arguments:
|
||||
attrs (dict): collection of attribute: value
|
||||
|
||||
root (str): The root path in Houdini to search in.
|
||||
Example:
|
||||
>> lsattrs({"id": "myId"})
|
||||
["myNode"]
|
||||
>> lsattr("id")
|
||||
["myNode", "myOtherNode"]
|
||||
|
||||
Returns:
|
||||
list
|
||||
list: Matching nodes that have attribute with value.
|
||||
"""
|
||||
|
||||
matches = set()
|
||||
nodes = list(hou.node("/obj").allNodes()) # returns generator object
|
||||
nodes += list(hou.node("/stage").allNodes())
|
||||
# Use allSubChildren() as allNodes() errors on nodes without
|
||||
# permission to enter without a means to continue of querying
|
||||
# the rest
|
||||
nodes = hou.node(root).allSubChildren()
|
||||
for node in nodes:
|
||||
for attr in attrs:
|
||||
if not node.parm(attr):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue