使形状节点的名称与父级相同
Making the name of shape node to be the same as the parent
如何使形状节点的名称与其父节点的名称相似? (假设每个 geometry/object 只有 1 个形状节点)
例如。 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
等
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
select 仅顶部组
如何使形状节点的名称与其父节点的名称相似? (假设每个 geometry/object 只有 1 个形状节点)
例如。 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
等
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
select 仅顶部组