将形状节点的名称与括号相同

2024-04-26 18:18:53 发布

您现在位置:Python中文网/ 问答频道 /正文

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

例如,父图形被称为test_geo1,但是它的形状节点是testing_geo2Shape,而不是{}

我试着做以下事情:

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等等


Tags: intest名称childtruefor节点all
1条回答
网友
1楼 · 发布于 2024-04-26 18:18:53
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]))

测试的层次结构如下:

^{pr2}$

仅选择顶部grp

相关问题 更多 >