Hey guys,
I need to find a way to retrieve the nodes that are referenced by the entire hierarchy used to cook a given node.
With node.references, node.inputAncestors, etc. I think I can get something, but Houdini has a visual representation of this already :
And this is exactly what I need. I want to know which nodes at the same level of the node selected are needed for the selected node.
Is there a function I don't know of that already does this ?
Thanks a lot,
Julien
Node dependencies in Python
3634 5 2- julien-b
- Member
- 66 posts
- Joined: 3月 2017
- Offline
- ralphymeijer
- Member
- 16 posts
- Joined: 3月 2015
- Offline
- julien-b
- Member
- 66 posts
- Joined: 3月 2017
- Offline
- Jonathan de Blok
- Member
- 274 posts
- Joined: 7月 2013
- Offline
https://bitbucket.org/jcdeblok/jdb_houdinitoolkit/src/master/python_panels/ [bitbucket.org]
Check my ‘visibility manager’ panel. It has some buttons to select the whole tree a node belongs to, or all below/above a node etc. There are a few python function in the source that are easy to rip out.
Check my ‘visibility manager’ panel. It has some buttons to select the whole tree a node belongs to, or all below/above a node etc. There are a few python function in the source that are easy to rip out.
More code, less clicks.
- julien-b
- Member
- 66 posts
- Joined: 3月 2017
- Offline
Thanks Jonathan, I will have a look.
In the meantime, I think I managed to get what I needed by writing a recursive function that inspects the references of a given list of nodes. The function find the references of each node, then look at their ancestors for new references, etc.
I don't think it's necessarily future proof, and I'll keep testing it further, but for now I think I got what I needed.
Please let me know if you guys feel like there is something wrong with what I'm doing.
In the meantime, I think I managed to get what I needed by writing a recursive function that inspects the references of a given list of nodes. The function find the references of each node, then look at their ancestors for new references, etc.
I don't think it's necessarily future proof, and I'll keep testing it further, but for now I think I got what I needed.
Please let me know if you guys feel like there is something wrong with what I'm doing.
### RETURNS REFERENCES FROM A GIVEN NODE ### ### Ignores the references inside a hda, as they are considered self contained ### def getReferences(node): references = [] if isNodeHDA(node): references = list(node.references(include_children=False)) ### Removes children if referenced in the hda ### for reference in references: if isNodeChildOf(reference,node): references.remove(reference) else: references = node.references(include_children=True) references = list(set(references)) ### Removes the node if it references itself ### if node in references: references.remove(node) return references ### RETURNS ALL DEPENDENCIES FOR A GIVEN NODE def getAllDependencies(nodes, level=0, maxdepth=10): dependencies = [] if level == maxdepth: return dependencies for node in nodes: references = getReferences(node) ## for each reference, get ancestors for reference in references: ancestors = reference.inputAncestors(include_ref_inputs=True,only_used_inputs=False) newDependencies = getAllDependencies(ancestors,level+1,maxdepth) newDependencies.append(reference) for dependency in newDependencies: if dependency not in dependencies: dependencies.append(dependency) result = [] for dependency in dependencies: if dependency not in nodes: result.append(dependency) return result
Edited by julien-b - 2020年8月6日 18:06:10
VFX Supervisor @ MPC London
- Pirminus
- Member
- 33 posts
- Joined: 2月 2015
- Offline
Hey julien-b,
I have stumbled across the same problem today and managed to solve it with a hscript command within python
https://www.sidefx.com/docs/houdini/commands/opdepend.html [www.sidefx.com]
so
should give you a list of dependency nodes.
cheers
I have stumbled across the same problem today and managed to solve it with a hscript command within python
https://www.sidefx.com/docs/houdini/commands/opdepend.html [www.sidefx.com]
so
hou.hscript("opdepend -d -e " + node.path())
should give you a list of dependency nodes.
cheers
Edited by Pirminus - 2024年9月26日 02:08:48
-
- Quick Links