这个 PyMEL 语句有什么作用?

What does this PyMEL statment do?

此语句出自实用maya编程一书。作者后来继续使用 xform 和 shape 作为我理解的 type()dir() 函数中的参数。

>>> xform, shape = pmc.polySphere()

为什么/如何 xform 和 shape 等于 pmc.polysphere?...它们不是多余的吗?实例化球体时无论如何都会创建形状节点?这会不会在以后创建其他形状时引起并发症?

xform 在脚本编辑器中是蓝色的,这是什么意思,如何用作变量名?

pmc.polySphere() returns 具有两个元素的序列。 The first is assigned to xform, and the second to shape.

>>> a, b = [1, 2]
>>> a
1
>>> b
2

再扩展一下答案。

你会期望执行 pmc.polySphere() 只会给你它的变换,但它实际上 returns 它的变换和形状节点的列表:[nt.Transform(u'pSphere1'), nt.PolySphere(u'polySphere1')]

您可以这样分配变量:

sphereObj = pmc.polySphere()
xform = sphereObj[0]
shape = sphereObj[1]

但是一次性将列表解包并分配给您的变量更具可读性和 Pythonic:

xform, shape = pmc.polySphere()

只要知道列表的长度,就可以做成一行:

a, b, c, d = [1, 2, 3, 4]

尽管大多数时候您可能只需要转换,因此您也可以随时这样做:

xform = pmc.polySphere()[0]