Yep, turns out a "for each" can give very strange results for a
MFloatPointArray... iterating with "for i in range(array.length())"
works properly -- thanks Damon!
a little hack i wrote to work around this problem is to use an iterator
function. nothing too smart really, just
simplifies code a bit (no more "list[i]+anotherList[j]" type of code
inside loops). It actually started as a safe way
to iterate over an iterator type (to not forget/skip "next" in iterating
them), but then got extended to support
array types as well.
def mIter(mayaIterator):
'''
shortcut method to iterate maya iterators and lists with foreach
'''
# iterator?
if hasattr(mayaIterator, "isDone"):
while not mayaIterator.isDone():
yield mayaIterator
mayaIterator.next()
# array?
elif hasattr(mayaIterator, "length"):
for i in xrange(mayaIterator.length()):
yield mayaIterator[i]
to use the code, you just write
points = om.MPointArray()
...
for i in mIter(points):
print i.x, i.y, i.z
--
http://groups.google.com/group/python_inside_maya