Mayaで言うところのlistRelatives -adコマンド
Mayaでは1行で出来るのに、Blenderでは、簡単には出来ない(?)らしく、自分で再帰関数を作ってやらないと出来ないっぽい。
↓オブジェクトを1つ選択した状態で実行すると、下の階層のオブジェクト名がすべてprintされる
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)を
hierarchyList.append(ob)に変えてやれば、名前じゃなくてオブジェクト自体の取得もできます。
ちなみに、listRelatives -cっぽいことをする方法はこちら
https://qiita.com/pekochun/items/48433271c9d7e20a0b7c
自分用メモ
ちょっと自信ないので、間違ってたら教えてください。