【发布时间】:2021-04-09 11:02:54
【问题描述】:
在 Maya 中尝试一些基本编程时,我遇到了“MitMeshPolygon”方法。被描述为: “这个类是多边形表面(网格)的迭代器。”
这似乎是我需要的,所以我更多地研究了迭代器,据我所知,迭代器本身应该是可迭代的,并且有一个 iter 方法。但是,当尝试对其进行迭代时,python 告诉我它不可迭代。
iterable = OpenMaya.MItMeshPolygon(dagPaths[0])
while not iterable.isDone():
print(iterable)
print(dir(iterable))
['class', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new ', '下一个', 'reduce', 'reduce_ex', 'repr', ' setattr', 'sizeof', 'str', 'subclasshook', 'swig_destroy' , 'weakref', 'center', 'className', 'count', 'currentItem', 'geomChanged', 'getArea', 'getAxisAtUV', 'getColor', 'getColorIndex', 'getColorIndices '、'getColors'、'getConnectedEdges'、'getConnectedFaces'、'getConnectedVertices'、'getEdges'、'getNormal'、'getNormals'、'g etPointAtUV','getPoints','getTriangle','getTriangles','getUV','getUVArea','getUVAtPoint','getUVIndex','getUVSetNames','getUVs','getVertices','hasColor','hasUVs' , 'hasValidTriangulation', 'index', 'isConnectedToEdge', 'isConnectedToFace', 'isConnectedToVertex', 'isConvex', 'isDone', 'isHoled', 'isLamina', 'isPlanar', 'isStarlike', 'isUVReversed', ' next','normalIndex','numColors','numConnectedEdges','numConnectedFaces','numTriangles','onBoundary','point','polygon','polygonVertexCount','reset','setIndex','setPoint' , 'setPoints', 'setUV', 'setUVs', 'tangentIndex', 'this', 'thisown', 'updateSurface', 'vertexIndex', 'zeroArea', 'zeroUVArea']
我想遍历所有多边形和“getArea”,但现在我不知道该怎么做,我读到的所有内容都告诉我迭代器应该是可迭代的,但程序告诉我不然。我在这里不明白什么?如何使用这些方法获取有关 DagPath 指示的对象的特定信息?
【问题讨论】:
-
for item in iterable:不起作用吗? -
请注意,有一个
__next__方法,因此您应该能够在while True:循环内调用next(iterable),一旦完成,它将引发StopIteration。 -
不重复。这个对象不是 Python 中标准意义上的迭代器。您必须以某种特定于 Maya 的方式与之交互。查看方法列表,
count、next和currentItem看起来可能是要走的路,但我对 Maya 的了解还不够,无法对应该如何使用这个东西有信心。跨度> -
@user2357112supportsMonica 为什么在
dir()的输出中列出了__next__? -
@00: 奇怪...这不在在线文档中,并且缺少所有迭代器都应该拥有的
__iter__。我猜这个东西可能有一半可以用作迭代器。
标签: python methods iterator maya-api