PDA

View Full Version : Art of Rigging - script questions!


woadiestyol
09-12-2008, 04:24 PM
Hey all,

I picked up the Art of Rigging books a while ago and am now finding the time to go through them (since I quit my accounting job and am starting Gnomon in a couple weeks :thumbsup:) I'm a complete MEL & programming newb, and came across a couple items in their stretchy IK script that were breezed over a bit and I'm trying to understand! Hopefully some kind soul might be able to explain these to me (and hopefully I'm not in violation of any copyright issues by posting parts of the script).

1. Using the "setParent" command when creating a UI window as follows:global proc cgTkStretchyIk ()
{

if (`window -q -ex stretchyIkWindow`) deleteUI stretchyIkWindow;

//Main Window
window -title "CG Toolkit - Auto Stretchy Joint Chain" -w 340 -h 50 stretchyIkWindow;

//Button Layouts
rowColumnLayout -nc 2 -cw 1 175 -cw 2 150;
text "Select RP or SC IK Handle: ";
button -label "Make Stretchy" -c "makeIkStretchy";
setParent..;

//Show Main Window Command
showWindow stretchyIkWindow;
}
Does this just say, "Okay I'm done defining the items in my window layout?" I've read through the MEL documentation but I don't really understand what's going on here!

2. Using the "eval" function to find the end effector of an IK handle and store it as $endJoint://Find the end joint where the ikHandle is located.
string $endJoint[];
$endJoint[0] = `eval ("ikHandle -q -endEffector " + $ikHandle)`;
select $endJoint[0];
$endJoint = `pickWalk -d up`;
$endJoint = `pickWalk -d down`;
I guess I'm not really sure what the "eval" function does even after reading the documentation on it. Why not just do it like this:$endJoint = 'ikHandle -q -endEffector $ikHandle'

Thanks in advance to anyone willing to take the time to explain this stuff to me! I'm really enjoying the books so far, but I get hung up on little things like this every now and then. I really want to get good at this stuff, so I don't just want to gloss over things I don't understand.

Cheers,

JP

Buexe
09-12-2008, 05:31 PM
the setParent command tells Maya that the current layout does not get more controls and/or other layouts, kind of like you described it although there is no such thing as a window layout in Maya. Imagine your GUI has different layouts and they have a hierarchical order with parent/child relationships and branches. In the case you specified the setParent command is kind of useless, because no other controls/layouts are specified after the setParent command.

Regarding the eval thing I guess it should work the way you described it without the eval thing. But maybe the authors had a reason to do it this way, so ... can`t really help on that one.

woadiestyol
09-12-2008, 09:55 PM
Thanks! I noticed that the setParent command was in the video tutorial and the script itself, but it wasn't shown in the book - I think because it's not actually necessary in this case.

As for the eval thing, again, it seemed to work the same when I did it my way...and there doesn't seem to be a reason (that I can find) for why it's there. I would understand if it was used for the sake of example, but there wasn't really a description of what the "eval" command does, and since there's not much documented about it in the MEL command reference, I was a bit confused.

Anyways, the parent thing makes more sense to me now...I'm still not sure what "eval" is used for, but I don't seem to need it here, so I'll just accept my confusion for the time being.

kiaran
09-12-2008, 10:09 PM
woadiestyol- I can't tell you why I used the eval command there. Maybe there was a reason, maybe not. It's been so long I don't remember. But if it works without, I wouldn't stress about it :)

As for 'eval' itself. It's a very handy command. Sometimes you need to build-up a long MEL command a peice at a time before executing it. For example, the curve command takes an argument for each vertex. So you can build up each vertex inside a loop like this:

//$allVertices is a list of vertices
string $cmd = "curve ";
for ($vert in $allVertices)
{
//Get vertex position
float $pos[] = `pointPosition $vert`;
//Add vertex to command
$cmd += ("-p " +$pos[0]+" "+$pos[1]+" "+$pos[2]);
}

//Now run the command to make a curve with the specified vertex positions
eval($cmd);

woadiestyol
09-13-2008, 03:38 PM
Awesome, I think I get it - you're basically storing a long command into a variable $cmd, then using eval to run the command (since there could be a ridiculous number of verticies).

Thanks for the explanation! And, of course, thanks for the really awesome books - some of the best of any computer books I've ever read. The book is so great about explaining why things are done, not just how. I feel like I've already leaned so much, and i've got hundreds of pages to go.

So props to a great author and community - where else would I get direct answers from an author (believe me, I've tried)?

ewerybody
09-15-2008, 07:24 AM
@woadiestyol: if you wanna know: eval runs commands. Most common use of eval is when you assemble each part of you command call and then want to evaluate it in one go. Something like:

string $cmd = "command -bla 3";
if ($bla)
$cmd = $cmd + " -zaozaaaa " + getNumberX($obj);
// you could even print it out to check it manually:
print ($cmd + "\n");
// then run the whole crp
eval($cmd);

EDIT:
oh.. already said ^^ good morning! *yaaaaaaaaaawn*
ok but there is evalDeffered as well. Sometimes it seems Maya does stuff before something different is finished. I you feel your stuff is executed a tick too early use evalDeffered and it will run the next time Maya goes idle.

When introducing to eval something might be importat: eval always uses global scope!!! So when trying to create arbitrary variables with eval they will be available in global scope a well! .. which is quite bad and actually a very stupid idea ( I had to find about that myself ... ;] )

okok, you won't use it now. Just to let you know.. ;]

woadiestyol
09-16-2008, 12:59 AM
Cool, thanks for the tips!! I'll keep this in mind next time I'm writing a script using these commands.

CGTalk Moderation
09-16-2008, 12:59 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.