2016-08-23 4 views
0

シェイプノードの名前を親ノードと同じ名前にするにはどうすればよいですか? (形状/オブジェクトごとに1つの形状ノードしかないと仮定して)シェイプノードの名前を親ノードと同じにする

たとえば、

all = cmds.ls(sl=True, dag=True, shapes=True) 
for shape in all: 
    prt = cmds.listRelatives(shape, parent=True) 
    for i in prt: 
     child = cmds.listRelatives(i, c = True) 
     for c in child: 
      cmds.rename(c, str(prt) + "Shape") 

と私は、このようなu_test_geo1__Shapeなど

階層をテストし

答えて

1
all = cmds.ls(sl=True, dag=True, shapes=True) 
for shape in all: 
    ''' 
     shape contain the dag path 
     exm.: 
     grp_a 
      grp_aShape 
      grp_b 
       grp_bShape 
     print cmds.ls('grp_a', dag=1, shapes=1) 
     >>('grp_a|grp_aShape', 'grp_b|grp_bShape') 
     now rename the object, we have already the dag path so 
     the input of the rename command is unique, you can also split the dag 
     path by '|'[0] as parent 
    ''' 
    cmds.rename(shape, "{0}Shape".format(cmds.listRelatives(shape, parent=True)[0])) 

など、いくつかのファンキーな名前を取得:parent_geoは、私は次のことをやってみましたが、その形状のノードがtesting_geo2Shape代わりのtest_geo1Shape

で、test_geo1と呼ばれていますのようでした:

grp_a 
    shape grp_a 
    grp_b 
      same name like shape grp_c 
grp_c 
    shape grp_c 
    grp_d 
      same name like shape grp_c 
grp_e 
    same name like shape grp_c 

先頭のgrpのみを選択

+0

lsでメッシュ形状を見つけるには、複数の中間形が検出されないようにするにはフラグni = Trueを使用する必要があります。名前を変更する前に、mayaが「新しい名前の名前を変更する」のを防ぐために名前が既に存在するかどうかをチェックする必要があるかもしれません。 – DrWeeny

+0

@ゴールドなので、私はzipとformatメソッドでテストします。すべてを選択する/単にノード/形状ノードなどを選択しますが、残念ながらコードを取得することはできません。後者のコードも同じです – dissidia

+0

@dissidia true、ネストされたグループまたは複数のシェイプ名前、私はそれを変更します –

関連する問題