使形状节点的名称与父

时间:2016-08-23 19:35:44

标签: python maya

如何使形状节点的名称与其父节点具有相似的名称? (假设每个几何/对象只有一个形状节点)

例如。 parent_geo被称为test_geo1,但其形状节点为testing_geo2Shape而不是test_geo1Shape

我尝试了以下操作:

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 个答案:

答案 0 :(得分: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]))

测试的层次结构如下:

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