View Full Version : total noob


TOPMO3
08 August 2007, 10:31 AM
-----------EDIT

Scroll to bottom

-----------EDIT

Hey folks,

forgive my noobiness, I'm just getting through the DIgital Tutors: Arists Guide to Mel.
I've rigged up my own models for a while now, and am trying to figure out how to write some MEL scripts to help me do so much more quickly. Question is this.

I have two objects selected. Then i run my script. How can I store the NUMBER of objects/nodes/items selected instead of their names?

I know i can do something like

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

and store the NAMES of the objects in that array, but how can i query that array to get the NUMBER of names stored in it?

This is probably so easy it's embarrassing. Please help a noob anyway. I dont want to be afraid of MEL anymore :)

Michael

Piddu
08 August 2007, 11:14 AM
Don't worry nobody born knowing mel already.
You should use the size commanda which returns the number of items in an array.
You should write:

string $objectArray[] = `ls -sl`;
int $numObjs = size($objectArray);

or

string $objectArray[] = `ls -sl`;
int $numObjs = `size $objectArray`;

That it is completely the same things.
Then pay attention: if you want to iterate the elements inside the array you mustn't reach the element $objectArray[$numObjs] because it doesn't exist.
The maximum element is $objectArray[$numObjs - 1], cause the array in mel are 0-indexed, in other words your first element is $objectArray[0], the second is $objectArray[1] and so on.

Bye

tbaypaul
08 August 2007, 05:35 PM
mel is really just the specific maya tool commands..like...move, extrude, ls and other. But the stuff that binds the commands together into a script is just the programming language c. So get a cheap used intro to c and that will explain alot of things about variables, data types and arrays.

TOPMO3
08 August 2007, 06:30 PM
thanks guy. I got several resources on mel. actualy a good book called Complete Maya Programming by David A. D. Gould. This book actualy explains everything really well. I just need to get my head around programming, like i had to get it around rigging.

thanks for the quick reply though, that was exactly what i needed to know!

TOPMO3
08 August 2007, 04:49 AM
-----EDIT

nevermind, got it! MEL rules, i jsut suck!!! :)

-----EDIT



hey folks,

I have a 2 joint chain. I select the last joint, and execute the following command:

string $myTest = pickWalk -d up;

Maya pickWalks up to the parent joint, but coughs up this error:

string $myTest = `pickWalk -d up`;
// Error: Cannot convert data of type string[] to type string. //

I also tried FIRST pickWalking up to the parent, then doing this:

string $myTest = `ls -sl`;

to put the selected item (parent joint) into the $myTest string. This ALSO gave me the same error. I want to basicaly store the parent of the selected joint in a string. I thought at first the problem was that maybe the 'pickWalk, and ls -sl commands were returning more than one result, but after just selecting the parent by themselves, and running pickWalk and ls -sl by themselves, i got one result, and it was the name of the parent joint.

Anyone have any idea?

Thanks
Michael

TOPMO3
08 August 2007, 05:42 AM
Hey again folks,

Well it looks like my first script might be finished, atleast it does what I want it to do, with no errors (that i've found yet), and I'm pretty stoked. But i'd like some feedback on it, maybe some ways I could save code, shortcuts, work-arounds, more efficient ways to code it. You get the idea.

Here's what I wanted the script to do. It's a basic "make me a controller" script. When you have your joint hierarchy setup, you make a basic nurb curve, move it over the joint, rotate it how you want, and then you start that lengthy process of making a group, constraining the group to the joint, deleting the constraint, parenting the curve to the group, freezing transforms, orienting the joint to the curve, then parenting the group to the joint of the parent. blah blah blah... i wrote the script to save time doign all that over and over again.

Here it is:

// MakeCON script
// Michael Panov 8/18/07


//declare the array of objects selected.

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

//declare the number of objects selected.

int $numObjects = size($myObjects);


// If more than 2 objects selected, error out.

if ( $numObjects == 2 )
{
//Declare 1st and 2nd item in array as CON and Joint respectively.
//Also create and declare a group named after the CON object with extention _GRP

string $conObj = $myObjects[0];
string $jointObj = $myObjects[1];
string $conGroup = `group -em -n ($conObj + "_GRP")`;

//The works

pointConstraint $jointObj $conGroup;
delete ($conGroup + "_pointConstraint1");
orientConstraint -offset 0 0 0 -weight 1 $jointObj $conGroup;
delete ($conGroup + "_orientConstraint1");
parent $conObj $conGroup;
FreezeTransformations $conObj;
orientConstraint -mo -weight 1 $conObj $jointObj;
select $jointObj;
pickWalk -d up -type nodes;

//Declare the parent of the joint selected
//and parentConstrain the controller group to it

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

parentConstraint -mo -weight 1 $jointParent $conGroup;
select -cl;

print ($conObj + " now controls " + $jointObj + ".");
}
else
error "More than 2 objects selected. First select the controler, then the joint.";

Please let me know what you guys think. Any feedback is appreciated!

Michael

CGTalk Moderation
08 August 2007, 05:42 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.


1