From 390c6d15a580f18b736dbb26670effe24719d974 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Thu, 10 Feb 2022 17:31:32 +0100 Subject: [PATCH] handle permissions and root more gracefully --- openpype/hosts/houdini/api/lib.py | 33 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/openpype/hosts/houdini/api/lib.py b/openpype/hosts/houdini/api/lib.py index 6e48791ce8..937863caba 100644 --- a/openpype/hosts/houdini/api/lib.py +++ b/openpype/hosts/houdini/api/lib.py @@ -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):