使用ls -sl返回一个转换。我能找到获得变换形状的唯一方法是使用getRelatives,但与其他工作流程相比,这看起来很糟糕。有没有更好的标准方法从变换中获取Shape?
在PyMEL中从变换获得形状的非常标准的方法:
transform.getShape()
要从选择列表中获取形状,可以执行以下操作,从而生成形状列表。
sel_shapes = [s.getShape() for s in pm.ls(sl=1)]
请注意某些变换没有形状。像一个组节点,它基本上是一个空变换。
请注意,自2018年起,pymel getShape()
存在缺陷(IMO),因为它假设每个节点只有一个形状,并非总是如此。 (就像99%的情况一样,虽然如此,所以我在挑剔)
然而; getShape()方法仅适用于变换nodeType。如果你有一个未知的节点类型,你试图解析它的网格或曲线,例如,通过说getShape(),你将要检查是否可以使用该方法。
if pm.nodeType(yourPyNode) == 'transform':
'shape = yourPyNode.getShape()
如果解析未知数:listRelatives()
命令,shape
或s
标志设置为true
selected_object = pm.ls(sl=True)[0]
shapes = pm.listRelatives(selected_object, s=True)
if len(shapes) > 0:
for shape in shapes:
# Do something with your shapes here
print('Shapes are: {}'.format(shape))
# or more pymel friendly
shapes = pm.selected_object.listRelatives(s=True)
for shape in shapes:
# Do something in here