The listRelatives -ad command in Maya In Maya, it can be done in one line, but in Blender, it seems that it can not be done easily (?), And it seems that you can not do it unless you create a recursive function yourself.
↓ If you execute with one object selected, all the object names in the lower hierarchy will be printed.
import bpy
def return_hierarchy(ob):
hierarchyList = []
def recurse(ob):
hierarchyList.append(ob.name)
if not len(ob.children) == 0:
for child in ob.children:
recurse(child)
return
recurse(ob)
return hierarchyList
selectList = bpy.context.selected_objects
his = return_hierarchy(selectList[0])
for hi in his:
print(hi)
hierarchyList.append (ob.name) If you change it to hierarchyList.append (ob), you can get the object itself instead of the name.
By the way, here's how to do something like listRelatives -c https://qiita.com/pekochun/items/48433271c9d7e20a0b7c
Personal notes I'm a little unsure, so please let me know if you make a mistake.
Recommended Posts