Python function 'node.children()'

   13733   1   4
User Avatar
1 posts
Joined: Nov. 2017
Hi big friends, i have a little question for you

it about python function ‘hou.node.children()’

that's returning always like this (<hou.SopNode of type sphere at /obj/geo1/subnet1/sphere1>,..)
it's seems like used absolute path for searching node look to me…

wonder how get relative path node not used absolute path.
(<hou.SopNode of type sphere at ./subnet1/sphere1.>,..) (when if current node is ‘/obj/geo1’)

have a any idea?
User Avatar
37 posts
Joined: Aug. 2015
All paths are absolute at the base. Relative paths are representations that are parsed by houdini to find the abs path of a node. They cant exist on their own and are meaningless without a relative point of origin.

use hou.node.relativePathTo(base_node) to get paths from one node to another.

In your case you can do this:
chl = myNode.children()
for child in chl:
    pathToParent = child.relativePathTo(myNode)
    pathToChild = myNode.relativePathTo(child)

But given in this case you are simply getting the path from the parent, relative paths are not very useful here; pathToParent would return ‘..’ for every child node, which simply means “up one level”. pathToChild would simply return the name of the child node, because the parent is like the current directory.

If you do:
You should get the abs path of the parent node.

hou.node.children() will get nodes one level down. For all children, including chilren of children, i think you need to use hou.node.allSubChildren(). Relative path would be more useful in that case.

hope this helps
  • Quick Links