View Full Version : Initialise MDoubleArray with Python list.

03 March 2009, 11:39 PM
This should be (and probably is) simple, but I really I can't figure it out. I'm just trying to initialise an MDoubleArray with a Python list, normally I'd just use a list, but I need it for an API command argument so it has to be an MDoubleArray.

I thought I could just do this:

import maya.OpenMaya as om
print om.MDoubleArray([1.0, 2.0, 3.0], 3)
Or at the most this:

array = [1.0, 2.0, 3.0]
print om.MDoubleArray(array, 3)
But both throw overloaded function with wrong argument errors.

Any suggestions?

03 March 2009, 10:37 AM
I suppose I have the same problem than you with another method (getScale).

I've try your lines et the error is:
# Error: Wrong number of arguments for overloaded function 'new_MDoubleArray'.
Possible C/C++ prototypes are:
MDoubleArray(MDoubleArray const &)
MDoubleArray(double const [],unsigned int)
MDoubleArray(float const [],unsigned int)
MDoubleArray(unsigned int,double)

I think the python maya interpretor can't find a matching constructor. I don't know how maya manages this kind of problems. How he convert la list to a float array (or a double array), if he do it. There is not a lot of documentation about that... :(

So if anyone have a solution...

This seems to work:
import maya.OpenMaya as om
myDoubleArray = om.MDoubleArray()

03 March 2009, 01:44 PM
That is what I did, but it's ugly!

03 March 2009, 02:06 PM
I'm agree with you... :(
There is not a lot of documentation about Maya Python API and types problems... If anyone have a workaround documentation, he don't hesitate! ;)

CGTalk Moderation
03 March 2009, 02:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.