Horvátth Szabolcs wrote:
> Might help someone in the hour of need when dealing with matrices:
> http://mayastation.typepad.com/maya-station/2009/09/overriding-__str__-for-maya-python-objects.html
>
> Cheers,
> Szabolcs
>
> >
>
>
Nice, you can patch iterators the same way to have iterable MMatrix
class, as we're doing in the pymel wrap of it :
def _patchMMatrix() :
def __len__(self):
""" Number of rows in the Maya api Matrix, ie 4.
Not to be confused with the number of components (16) given
by the size method """
return 4
type.__setattr__(MMatrix, '__len__', __len__)
def __iter__(self):
""" Iterates on all 4 rows of a Maya api Matrix """
for r in xrange(4) :
yield
Array([_api.MScriptUtil.getDoubleArrayItem(_api.MMatrix.__getitem__(self,
r), c) for c in xrange(4)])
type.__setattr__(MMatrix, '__iter__', __iter__)
Note : Array is the generic class defined in pymel but you could yield a
regular list or nested list if you prefer.
Still, swig is a pretty complex tool that allows a lot of customisation
on how it wraps the C++ methods, and I think the wrap done by Autodesk
falls a bit short as it could, and should, provide these, and correct
multiple return values, eliminating the need for MScriptUtil "built-in".
--
Olivier Renouard
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---