♻️ enhance sop node selection logic

if selected node is sop node, it will be used for path, otherwise it will try to find output node with lowest index under selected node
This commit is contained in:
Ondrej Samohel 2023-04-13 16:44:19 +02:00
parent 9a3fe48125
commit 0d1870ff5a
No known key found for this signature in database
GPG key ID: 02376E18990A97C6

View file

@ -38,13 +38,17 @@ class CreateBGEO(plugin.HoudiniCreator):
}
if self.selected_nodes:
parms["soppath"] = self.selected_nodes[0].path()
# try to find output node
for child in self.selected_nodes[0].children():
if child.type().name() == "output":
parms["soppath"] = child.path()
break
# if selection is on SOP level, use it
if isinstance(self.selected_nodes[0], hou.SopNode):
parms["soppath"] = self.selected_nodes[0].path()
else:
# try to find output node with the lowest index
outputs = [
child for child in self.selected_nodes[0].children()
if child.type().name() == "output"
]
outputs.sort(key=lambda output: output.evalParm("outputidx"))
parms["soppath"] = outputs[0].path()
instance_node.setParms(parms)
instance_node.parm("trange").set(1)