PDA

View Full Version : Python: how to create a MEL command with an array argument?


pascal
07-03-2007, 10:35 AM
Hello,

I would like to create a python plugin wich create a MEL command that can accept an array as one of it's argument.
So, calling this command would look like something as this:
{
float $test[] = {1,2,3};
myCommand -v $test;
}

The command creation is ok, as well as getting the values for the different arguments.
My trouble is how to get the array in python?

I already did this with the API using MArgList.get(unsigned int& index, MDoubleArray & ret)
But this is not avalaible with python...

I'm still starting python, so any hint is welcome!
Thanks,
Pascal.

pascal
07-31-2007, 09:18 PM
Wohoo!

I finally have a solution, thanks to autodesk support!

It uses MArgList:: asDoubleArray, but the trick is that it requires a pointer for the argument's index, wich is created using MScriptUtil.

It looks like this:

# The index of the command's argument
argsIdx=1
# This is to get a pointer to the index's value
MScript = OpenMaya.MScriptUtil()
MScript.createFromInt(argsIdx)
argsIdxPtr = MScript.asUintPtr()
# Get the array argument values into dataArray
dataArray = args.asDoubleArray(argsIdxPtr)

Hope it will help someone ;)

Pascal.

CGTalk Moderation
07-31-2007, 09:18 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.