git.lucas.co / hou-control
SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git

python3.13libs/hc/hcvisibility.py (1.2K)

 1 import hou
 2 
 3 
 4 def childCategory(node):
 5     """The name of the category of nodes this node contains, or ''.
 6 
 7     hou.Node.childTypeCategory() returns None for nodes that cannot have
 8     children, which is most of them below the object level.
 9     """
10     category = node.childTypeCategory()
11     return category.name() if category is not None else ''
12 
13 
14 def collect_visible_nodes(nodes):
15     """Display nodes of every visible SOP container reachable from `nodes`.
16 
17     Walks down through displayed object subnetworks, collecting the display
18     node of each displayed SOP container. Takes and returns plain hou.Node.
19     """
20     stack = list(nodes)
21     visible_nodes = []
22 
23     while stack:
24         node = stack.pop()
25         category = childCategory(node)
26 
27         if category == 'Sop' and node.isDisplayFlagSet():
28             if node.type().name() == 'cam':
29                 continue
30             display_node = node.displayNode()
31             if display_node is not None:
32                 visible_nodes.append(display_node)
33             continue
34 
35         if (category == 'Object'
36                 and node.isSubNetwork()
37                 and node.isDisplayFlagSet()):
38             stack.extend(node.children())
39 
40     return visible_nodes