View Full Version : Trouble with arrays and matrices.

11 November 2006, 09:53 AM
Doh!!! Should have posted this in the MEL section of the forum... Sorry 4 this.

I'm used to code in various languages but I'm kinda new to MEL. I have trouble dealing with its limitations on arrays.

I need to create a custom posing system. Therefore I need to store transformations together with my selected objects.

Ok, so I store the objects selection in a basic string array.

string $selectionList[] = `ls -sl`;

I'd like to store the transformatiom matrix (float[16]) and have an extra index refering to the index of the according selected object. This way it's easy to refer to an objects transform matrix : $selectionList[INDEX] matix is float[INDEX][16];

I can't use float arrays with multiple dimensions. :banghead: A workaround : MEL supports matrices with a specified size so... I query for the number of selected objects and I know how many elements are in a float 'matrix' that I'll query later with the xform -q -m. (there are 16)
So I know the size of the two dimensions in the matrix

int $cnt = size ($selectionList);
matrix $storedTransforms[$cnt][16];

int $i;
for ($i=0 ; $i<$cnt ; ++$i){
$storedTransforms[$i][] = `xform -q -m -os $selectionList[$i]`;

MEL doesn't accept a variable in the matrix' declaration :
matrix $storedTransforms[$cnt][16];

This doesn't work either :
$storedTransforms[$i][] = `xform -q -m -os $selectionList[$i]`;
$storedTransforms[$i] = `xform -q -m -os $selectionList[$i]`;

Hope everything's clear enough.

How can I make this stuff work properly????

11 November 2006, 01:46 PM
Ok, maybe I was looking too far... I found another solution.

Nevermind but the fact remains. MEL is quite a b#*t$ to store custom data.

11 November 2006, 01:48 AM
you really sound like maybe the c++ api is what you should be learning...mel is a scripting language made for maya...not like other scripting languages you may doesn't have multi dimensional array or structures......and matrix only looks like a 4d array...when queried it returns a 1d has it's limitations...and you can include mel inside of your api plugins....

You are describing maya's vertex, face and edge arrays in the api....all of that type of associative data arrays are detailed in David Gould's book vol 2 of complete maya excellent reference...

11 November 2006, 05:19 AM
yeah, that mel limitation bugged me a little as well ... so I wrote some wrapper functions that made handling of matrices and arrays a bit easier, check out:

hope it helps,

11 November 2006, 01:51 PM
Thx, mate.

CGTalk Moderation
11 November 2006, 01:51 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.