iterating through iterables is crazy talk!

(pass it on: http://code.google.com/p/pymel/wiki/PythonAPI)

-chad


On Oct 1, 2009, at 4:26 PM, Paul Molodowitch wrote:

>
> Some array types are iterable - MDoubleArray, for instance.  And,
> really, since they've implemented __getitem__, all they really need is
> __len__ - which would just be a straight wrap of length() - and it
> would work beautifully...
>
> I guess I should just resign myself to always writing c-code in python
> when it comes to the API... but every so often, I try to do something
> pythonic, and it works, and I get all excited, and start trying other
> crazy things!
>
> - Paul
>
> On Thu, Oct 1, 2009 at 3:41 PM, Chad Vernon <[email protected]>  
> wrote:
>> You can't iterate API array types like normal Python iterables.
>> You have to do:
>>
>> for dag in range(dagArray.length()):
>>     # blah
>>
>> On Thu, Oct 1, 2009 at 3:38 PM, barnabas79 <[email protected]>  
>> wrote:
>>>
>>> The subject says it all...
>>>
>>> import maya.OpenMaya as om
>>> sel = om.MSelectionList()
>>> sel.append('persp')
>>> sel.add('persp')
>>> dag = om.MDagPath()
>>> comp = om.MObject()
>>> sel.getDagPath(0, dag, comp)
>>> dagArray = om.MDagPathArray()
>>> dagArray.append(dag)
>>> dagArray.append(dag)
>>>
>>> numElements = 0
>>> for dag in dagArray:
>>>        numElements += 1
>>>        if numElements > 10:
>>>                print "Oh noes!"
>>>                break
>>>
>>
>>
>>>
>>
>
> >


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to