CGTalk > Techniques > Character Rigging
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-10-2013, 02:14 PM   #1
gagex2z
PRO
portfolio
gagex2z
Tampa, USA
 
Join Date: May 2011
Posts: 100
Rig automation help

I'm trying to learn how to automate my rigging setups. There are many problems and I'm certain I could be writing my code much better. However, right now the main problem I want to fix is the fact that my script will work if I select it in chunks, but not as a whole.

Any assistance is greatly appreciated.


http://www.youtube.com/watch?v=gh6Z...eature=youtu.be


This is my current script:

The main issue is that the script will not run in one click. I have to run the script get an error, then run the script again from the rename the pole vector part to the end in order to get the setup to complete.

I don't understand this.

//Jasons Arm setup


// Create arm joints

joint -p 4.004508 9.963554 0 ;
joint -p 14.009024 9.963554 -0.869017 ;
joint -e -zso -oj xyz -sao yup joint1;
joint -p 24 9.963554 0 ;
joint -e -zso -oj xyz -sao yup joint2;
joint -p 26 9.963554 0 ;
joint -e -zso -oj xyz -sao yup joint3;

// Rename your joints


rename "joint1" "L_shoulder";
// Result: L_shoulder //
pickWalk -d down;
// Result: joint2 //
rename "joint2" "L_elbow";
// Result: L_elbow //
pickWalk -d down;
// Result: joint3 //
rename "joint3" "L_wrist";
// Result: L_wrist //
pickWalk -d down;
// Result: joint4 //
rename "joint4" "L_palm";
// Result: L_palm //


//Build the Ik setup


select -r L_shoulder.rotatePivot ;
select -tgl L_wrist.rotatePivot ;
ikHandle -s sticky;
// Result: ikHandle1 effector1 //
select -cl ;
select -r ikHandle1 ;
rename "ikHandle1" "L_arm_IKRP";
// Result: L_arm_IKRP //


// create the IK control

curve -d 1 -p -2 2 0 -p 2 2 0 -p 2 -2 0 -p -2 -2 0 -p -2 2 0 -k 0 -k 1 -k 2 -k 3 -k 4 ;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
group; xform -os -piv 0 0 0;
select -tgl L_wrist ;
parent;

setAttr "group1.translateX" 0;
setAttr "group1.translateY" 0;
setAttr "group1.translateZ" 0;
setAttr "group1.rotateX" 0;
setAttr "group1.rotateY" 0;
setAttr "group1.rotateZ" 0;

parent -w;

rename "curve1" "L_IK_wrist_control";

rename "group1" "L_IK_wrist_control_grp";




//Make the IK blend attribute


select -r L_IK_wrist_control;

addAttr -longName IK_2_FK_Switch -defaultValue 0

-maxValue 1 -minValue 0 -keyable true;




//Connect the control to the Ik handle

select -cl ;
select -r L_arm_IKRP ;
select -tgl L_IK_wrist_control ;
parent;

// make the pole Vector


textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t "Le";

select -r curve2 curve3 ;
select -tgl curve1 ;
parent;

makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

pickWalk -d down;
// Result: curveShape2 curveShape3 //
select -tgl curve1 ;
parent-r-s;
// Result: curveShape2 curveShape3 //
select -cl ;
select -r curve1 ;
select -cl ;
select -r curve1 ;

parent -w;

CenterPivot;
xform -cp;

makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

group; xform -os -piv 0 0 0;

CenterPivot;
xform -cp

rename "curve1" "L_arm_PV";

rename "group1" "L_arm_PV_grp";



//Delete the empty text group


select -r Text_Le_1 ;

doDelete;



// Position the PV

select -r L_arm_PV_grp ;

move -rpr 14.009024 9.963554 -0.869017 ;
move -r -os -wd 0 0 -12.086826 ;
select -cl ;
select -r L_arm_PV ;
select -tgl L_arm_IKRP ;
poleVectorConstraint -weight 1;
 
Old 05-27-2013, 01:50 PM   #2
Pahuska
Veteran
 
Pahuska's Avatar
portfolio
FERRACHAT Guillaume
Maya Rigging/Scripting
Valence, France
 
Join Date: Feb 2012
Posts: 79
Hello,

I haven't been on cgTalk for 2 weeks so i'm a little late, but there's no answer so I guess you still need some help.

First of all, the reason of the error is simply because there is no ";" after "xform -cp". Maya understands that you want to center the pivot of an object called "rename", wich doesn't exist and not on the selected object. You should turn on "history > line numbers in errors". It will be easier to find and fix the errors.

Now just a few advices to write your code better :


Code:
// Create arm joints joint -p 4.004508 9.963554 0 ; joint -p 14.009024 9.963554 -0.869017 ; joint -e -zso -oj xyz -sao yup joint1; joint -p 24 9.963554 0 ; joint -e -zso -oj xyz -sao yup joint2; joint -p 26 9.963554 0 ; joint -e -zso -oj xyz -sao yup joint3; // Rename your joints rename "joint1" "L_shoulder"; // Result: L_shoulder // pickWalk -d down; // Result: joint2 // rename "joint2" "L_elbow"; // Result: L_elbow // pickWalk -d down; // Result: joint3 // rename "joint3" "L_wrist"; // Result: L_wrist // pickWalk -d down; // Result: joint4 // rename "joint4" "L_palm"; // Result: L_palm //


There's safer and shorter way to do that. As you said in your video, you need a blank scene or you may encounter errors. If you take a look at this : http://download.autodesk.com/global...ands/index.html you'll see that every command that creates an object in your scene have the -name (or -n) flag. It means you can name your joint when you create it, instead of creating it, then renaming it.
Another helpful thing about naming : most commands have a return value. The joint command return a string.
If you write this :
$LShoulder = `joint -p 4.004508 9.963554 0`;
print $LShoulder;

it will create a joint and print its name. Now you can use the $LShoulder variable instead of the real name of the joint, and avoid name clashes. Basically, the safest way to write your code would be :
Code:
$LShoulder = `joint -p 4.004508 9.963554 0 -name "L_shoulder"`; $LElbow = `joint -p 14.009024 9.963554 -0.869017 -name "L_elbow"` ; joint -e -zso -oj xyz -sao yup $LShoulder;


In your video, at about 8:50 you say that you don't know how to use locators to place your joints. It's pretty easy, you need to use 2 scripts, or 2 procedures. The first one will create locators, with a default bipedal position, then you place them where you want and execute the second part that creates the joints, IK, etc... it should look like that :

Code:
proc locs(){ //create some locators and set a default position spaceLocator -name "L_shoulder_loc"; xform -ws -t 0 10 0 "L_shoulder_loc"; spaceLocator -name "L_elbow_loc"; xform -ws -t 10 10 -2 "L_elbow_loc"; spaceLocator -name "L_wrist_loc"; xform -ws -t 20 10 0 "L_wrist_loc"; } proc rig(){ //read the locators world position and put it in a variable float $L_shoulder_p[] = `xform -q -ws -t "L_shoulder_loc"`; float $L_elbow_p[] = `xform -q -ws -t "L_elbow_loc"`; float $L_wrist_p[] = `xform -q -ws -t "L_wrist_loc"`; //create the joints joint -p $L_shoulder_p[0] $L_shoulder_p[1] $L_shoulder_p[2] -name "L_shoulder"; joint -p $L_elbow_p[0] $L_elbow_p[1] $L_elbow_p[2] -name "L_elbow"; joint -p $L_wrist_p[0] $L_wrist_p[1] $L_wrist_p[2] -name "L_wrist"; //... }


Now if you execute this code and write locs in the command line, you will create the locators. You move them where you want and then write rig in the command line, it will create the joints.

The xform commands in the first procedure moves the locators. In the second procedure I added the -q (-query) flag to put the world coordinates of the locators in one variable, then I read the variable to create the joints at the correct coordinates.

You can use procedures to create some tools that you're going to use a lot in your code. Like a group freezing tool, a shape parenting tool, and maybe a snap tool, based on a selection, so you don't have to write the same code again and again. In my latest autorig, I wrote a single function (python's procedures) with a few exceptions that I execute 4 times to have 2 arms and 2 legs. It saves a lot a lines.
 
Old 05-27-2013, 02:07 PM   #3
gagex2z
PRO
portfolio
gagex2z
Tampa, USA
 
Join Date: May 2011
Posts: 100
Quote:
Originally Posted by Pahuska
Hello,

I haven't been on cgTalk for 2 weeks so i'm a little late, but there's no answer so I guess you still need some help.

First of all, the reason of the error is simply because there is no ";" after "xform -cp". Maya understands that you want to center the pivot of an object called "rename", wich doesn't exist and not on the selected object. You should turn on "history > line numbers in errors". It will be easier to find and fix the errors.

Now just a few advices to write your code better :


Code:
// Create arm joints joint -p 4.004508 9.963554 0 ; joint -p 14.009024 9.963554 -0.869017 ; joint -e -zso -oj xyz -sao yup joint1; joint -p 24 9.963554 0 ; joint -e -zso -oj xyz -sao yup joint2; joint -p 26 9.963554 0 ; joint -e -zso -oj xyz -sao yup joint3; // Rename your joints rename "joint1" "L_shoulder"; // Result: L_shoulder // pickWalk -d down; // Result: joint2 // rename "joint2" "L_elbow"; // Result: L_elbow // pickWalk -d down; // Result: joint3 // rename "joint3" "L_wrist"; // Result: L_wrist // pickWalk -d down; // Result: joint4 // rename "joint4" "L_palm"; // Result: L_palm //


There's safer and shorter way to do that. As you said in your video, you need a blank scene or you may encounter errors. If you take a look at this : http://download.autodesk.com/global...ands/index.html you'll see that every command that creates an object in your scene have the -name (or -n) flag. It means you can name your joint when you create it, instead of creating it, then renaming it.
Another helpful thing about naming : most commands have a return value. The joint command return a string.
If you write this :
$LShoulder = `joint -p 4.004508 9.963554 0`;
print $LShoulder;

it will create a joint and print its name. Now you can use the $LShoulder variable instead of the real name of the joint, and avoid name clashes. Basically, the safest way to write your code would be :
Code:
$LShoulder = `joint -p 4.004508 9.963554 0 -name "L_shoulder"`; $LElbow = `joint -p 14.009024 9.963554 -0.869017 -name "L_elbow"` ; joint -e -zso -oj xyz -sao yup $LShoulder;


In your video, at about 8:50 you say that you don't know how to use locators to place your joints. It's pretty easy, you need to use 2 scripts, or 2 procedures. The first one will create locators, with a default bipedal position, then you place them where you want and execute the second part that creates the joints, IK, etc... it should look like that :

Code:
proc locs(){ //create some locators and set a default position spaceLocator -name "L_shoulder_loc"; xform -ws -t 0 10 0 "L_shoulder_loc"; spaceLocator -name "L_elbow_loc"; xform -ws -t 10 10 -2 "L_elbow_loc"; spaceLocator -name "L_wrist_loc"; xform -ws -t 20 10 0 "L_wrist_loc"; } proc rig(){ //read the locators world position and put it in a variable float $L_shoulder_p[] = `xform -q -ws -t "L_shoulder_loc"`; float $L_elbow_p[] = `xform -q -ws -t "L_elbow_loc"`; float $L_wrist_p[] = `xform -q -ws -t "L_wrist_loc"`; //create the joints joint -p $L_shoulder_p[0] $L_shoulder_p[1] $L_shoulder_p[2] -name "L_shoulder"; joint -p $L_elbow_p[0] $L_elbow_p[1] $L_elbow_p[2] -name "L_elbow"; joint -p $L_wrist_p[0] $L_wrist_p[1] $L_wrist_p[2] -name "L_wrist"; //... }


Now if you execute this code and write locs in the command line, you will create the locators. You move them where you want and then write rig in the command line, it will create the joints.

The xform commands in the first procedure moves the locators. In the second procedure I added the -q (-query) flag to put the world coordinates of the locators in one variable, then I read the variable to create the joints at the correct coordinates.

You can use procedures to create some tools that you're going to use a lot in your code. Like a group freezing tool, a shape parenting tool, and maybe a snap tool, based on a selection, so you don't have to write the same code again and again. In my latest autorig, I wrote a single function (python's procedures) with a few exceptions that I execute 4 times to have 2 arms and 2 legs. It saves a lot a lines.


Thanks for the really detailed and informative post. I'm only beginning to dip my foot in the mel world. I'm fairly intermediate level when it comes to in software rigging setups, but I'm getting to the point now where I can appreciate being able to write a script to automate repetitive tasks.

Thank you for the help, I'm sure this must be pretty basic stuff for you but I appreciate the help. I'm still debating whether or not to get the "Melscripting a character rig" book for maya. Do you think it would be too complicated for limited understanding of mel?

Do you recommend python or mel for automated tasks?
 
Old 05-27-2013, 04:50 PM   #4
Pahuska
Veteran
 
Pahuska's Avatar
portfolio
FERRACHAT Guillaume
Maya Rigging/Scripting
Valence, France
 
Join Date: Feb 2012
Posts: 79
I don't have the "Melscripting a charater rig" book, but all I can say is that when I started to write some MEL lines in 2011, all I needed was this : http://download.autodesk.com/global...mber=d28e663528 and the commands list

I'd say that it's better because it's about MEL, and not only about MEL scripting a character rig. The MEL language is pretty easy, and I think that when you have read Maya User's guide, you won't need another book to figure out how to write an autorig. Here's what you have to keep in mind, in my opinion :

- Keep it clean and as short as possible, use comments ( // your comment ) to describe what you do

- Keep it userfriendly, 2 buttons, some check boxes and a maybe a few intFields

- as I said in my first post, build some kind of internal tools. It's better to have one procedure with a lot of variables than a lot of copy/paste, because if you want to change something, you change it only once.

- Use the commands list and nodes list, you may even discover awesome nodes you never heard about

Quote:
Do you recommend python or mel for automated tasks?


It's difficult to answer this. I have some friends that prefers MEL, but for my part, now that I'm mostly using Python, whenever I try to write something in MEL, it feels like having a wooden sword when I could have a nuclear bomb... With Python, you can get out of maya, there's a lot of modules, you can even write some xml, wich is great, and variables in python are awesome, you can do everything
In my opinion, python is way better, but it's easier to start with MEL, and get into python later.
 
Old 05-28-2013, 01:58 PM   #5
nfd77
Aspiring Artist
 
nfd77's Avatar
portfolio
Nick DuPree
Chicago, USA
 
Join Date: May 2013
Posts: 388
Start off with MEL because you can just troll around the script editor to see what is going on. If you need the functionality of Python you can make the switch, but I have found that MEL works just fine for the purpose of rigging.

If you want you can thumb through my script to see how things are layed out, check out RigHelper

Just open up the MEL script in a text editor and start digging. I have a good amount of comments and the code is relatively clean. I find that the best way to learn is by example.

I hope this helps.
 
Old 05-28-2013, 01:58 PM   #6
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:57 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.