PDA

View Full Version : Picking a single value from a vector array


martin8910
10-27-2011, 12:08 AM
Hi!
I working on a bipedBodyrig script(MEL):
- I create locators that the user place for joint positions.
- All of those is stored in a string array list.

When I need to get the information of those locators position and use for my joint-creation i run into a problem. I cant be able to get the syntax to work for picking a single value of a vector and put as position for my joint. Here is a example:
//Find selection
string $selecion = `ls -sl`;
//Declare a vector value as a array
vector $selectionPosition[];
//Get position of selection and store in vector
$selectionPosition[0] = `xform -q -t`;

//Create joint and put value of vector on it
joint -p $selectionPosition[0];

So the last line gives me a error of:
// Error: line 1: Error while parsing arguments. //

stooch
10-27-2011, 12:52 AM
no, the first line is giving you the error, just like the trace is telling you...

string $selecion = `ls -sl`; is invalid.

`ls -sl` returns an array. you cant assign an array to a string.

you must declare an array first..

string $all[]; //this is an array string declaration. note the [] .

$all = `ls -sl`; //now you can assign the selection. note how im not using a [] here.

you can see this for yourself in the example for the "ls" command in the command docs. I recommend you look there first because every command has code examples.

mel sucks btw, learn python.

Koochy
10-27-2011, 01:05 AM
I'm not so good with MEL, so hopefully someone with more experience can explain this to you. I managed to get this to work though:

$sel = `ls -sl`;
float $selectPosition[] = `xform -q -t`;
joint -p $selectPosition[0] $selectPosition[1] $selectPosition[2];

martin8910
10-27-2011, 09:39 AM
no, the first line is giving you the error, just like the trace is telling you...

string $selecion = `ls -sl`; is invalid.

`ls -sl` returns an array. you cant assign an array to a string.

you must declare an array first..

string $all[]; //this is an array string declaration. note the [] .

$all = `ls -sl`; //now you can assign the selection. note how im not using a [] here.

you can see this for yourself in the example for the "ls" command in the command docs. I recommend you look there first because every command has code examples.

mel sucks btw, learn python.

Thanks for the explanation. Although i still have to solve the problem with the last line to get a single value from my string in that array.
Any idea how i could do this easier in Python?

I have a hard time learning Python in Maya sense i know that I need(i think) to wrap the python code into the MEL commands.

martin8910
10-27-2011, 09:41 AM
I'm not so good with MEL, so hopefully someone with more experience can explain this to you. I managed to get this to work though:

$sel = `ls -sl`;
float $selectPosition[] = `xform -q -t`;
joint -p $selectPosition[0] $selectPosition[1] $selectPosition[2];

Thanks Koochy, it works great if i have one object, but I need to have pack of locators listed into that array and pick up the X Y and Z from each on of them.

Azrail
10-27-2011, 09:48 AM
its not working because you're trying to assign a float array value to a vector... unfortunately this is the way most mel commands work - the xform actually returns a float3 array i.e. {1,2,3};
so to convert it to a vector variable you should do something like:

float $tmp[] = `xform -q -ws -t `;
vector $positions[];
$positions[0] = <<$tmp[0], $tmp[1], $tmp[2]>>;
// Result: <<5.624457, 0, 15.183661>> //

This example works, however sometimes you need to enclose the $tmp[n] thingy in parenthesis, or it yields a Sytax Error.

CGTalk Moderation
10-27-2011, 09:48 AM
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.