0
1

More than 3 years have passed since last update.

Blenderで選択したオブジェクト階層をすべてサーチするScript

Posted at

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

自分用メモ
ちょっと自信ないので、間違ってたら教えてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1