Message 1 of 3
Python iteration with API?
Not applicable
11-03-2009
10:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Using a simple iterator class in python I would like to use a for next loop. I really hate using a while loop, as eventually I will forget to type "stuff.next()" in the while part and maya will implode forever.
This code prints out the items that are currently selected.
Under the python documentation it seems that I should be able to loop through
iterators like this..
This returns the error
# TypeError: 'MItSelectionList' object is not callable #
Is there any general way to use iterator API functions in python without while loops?
Using a simple iterator class in python I would like to use a for next loop. I really hate using a while loop, as eventually I will forget to type "stuff.next()" in the while part and maya will implode forever.
This code prints out the items that are currently selected.
import maya.OpenMaya as OM
#Assign all selected objects to a selection list
list = OM.MSelectionList()
OM.MGlobal_getActiveSelectionList(list)
stuff = OM.MItSelectionList(list)
while not stuff.isDone():
dpath= OM.MDagPath()
stuff.getDagPath(dpath)
print dpath.partialPathName()
stuff.next()
Under the python documentation it seems that I should be able to loop through
iterators like this..
for item in iter(stuff):
This returns the error
# TypeError: 'MItSelectionList' object is not callable #
Is there any general way to use iterator API functions in python without while loops?