3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Maya | 親ノードを順に取得する

Last updated at Posted at 2016-11-09

選択したノードからさかのぼり、親ノードを取得していく。

MayaCmds版
import maya.cmds as cmds

def get_parent(node):
    parent = cmds.listRelatives(node, parent=True, path=True)
    if parent:
        yield parent
        for p in get_parent(parent):
            yield p

for node in get_parent(cmds.ls(selection=True)):
    print node
PyMel版
import pymel.core as pm

def get_parent(node):
    parent = pm.listRelatives(node, parent=True)
    if parent:
        yield parent
        for p in get_parent(parent):
            yield p

for node in get_parent(pm.selected()):
    print node

null1を選択してスクリプトを実行すると、次の結果が得られる。
image

[nt.Transform(u'group1')]
[nt.Transform(u'group2')]
[nt.Transform(u'group3')]
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?