syntax error stretchy joints script

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 05 May 2006   #1
syntax error stretchy joints script

so im getting a syntax error on this first line of the script

global proc ggmStretchyJoints(int $numJoints){

if ($numJoints < 1){
error ("you need to have at least 1 joint in between these two joints");
}


problem is, i cannot proceed past a certain point unless this line of code is executed.

unfortunately im not familiar enough with mel yet to see the problem but i cannot proceed with rigging until it is solved.

thanks in advance

-chris-
 
Old 05 May 2006   #2
Is that the exact line of code? If so, let's change the code formatting slightly:

global proc ggmStretchyJoints(int $numJoints)
{
if ($numJoints < 1)
{
error ("you need to have at least 1 joint in between these two joints");
}

You're missing another parenthesis, to essentially, close the procedure.
 
Old 05 May 2006   #3
yeah i added the parenthesis down on the bottom but i still get the error

$numjoints is an undeclared variable, i followed through everything and for some reason i dont get why it's not declaring numjoints here is the entire script

// ================================================== ========================
// ggmStretchyJoints.mel
// 2005 Geordie Martinez
// Just give me credit for it, pal. That's all I ask.
//
// DESCRIPTION: Builds stretchy joints between two joints
// in a chain.
//
// NOTES: You're creating stretchy joints
// so you should only do this between two inline joints, not
// between the first and third or forth in an IK chain, but
// between EVERY joint in an IK chain.
// MUST have rivet.mel installed from highend3D.com
//
// VERSION 1.0
//
//
// SELECT the ORIGIN JOINT and SHIFT SELECT THE INSERTION JOINT
// Enter the number of joints you want IN BETWEEN the two existing joints
// I've defaulted it to 2 joints, but it could be any number.
// ================================================== ========================

global proc ggmStretchyJoints(int $numJoints){

if ($numJoints < 1){
error ("you need to have at least 1 joint in between these two joints");
}}


//select the start and end joints respectively
string $sel[] = `ls -type joint -sl`;



// create a locator at Origin Joint
string $loc1[] = `spaceLocator -p 0 0 0`;
delete `pointConstraint $sel[0] $loc1[0]`;

// create a locator at Insertion Joint
string $loc2[] = `spaceLocator -p 0 0 0`;
delete `pointConstraint $sel[1] $loc2[0]`;

//now measure the distance between them with a distanceBetween node
// you'll use this to move the nurbs plane into the right spot
string $distance1 = `createNode distanceBetween`;
connectAttr ($loc1[0] + ".translate") ($distance1 + ".point1");
connectAttr ($loc2[0] + ".translate") ($distance1 + ".point2");

// create a nurbs plane of known proportions
string $nurbsPlane1[] =`nurbsPlane -p 0 0 0 -ax 0 1 0 -w 1 -lr 1 -d 3 -u 1 -v 1 -ch 0`;
subdivDisplaySmoothness -smoothness 3;
// parent it to the source joint so
// its rotate, translate all become those of origin joint
parent $nurbsPlane1[0] $sel[0];

// setting all the rotate and translate to zero moves it into the correct position
setAttr ($nurbsPlane1[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.5);
setAttr ( $nurbsPlane1[0] + ".sx") (`getAttr ($distance1 + ".distance")`);
setAttr ($nurbsPlane1[0] + ".ty") 0;
setAttr ($nurbsPlane1[0] + ".tz") 0;
setAttr ($nurbsPlane1[0] + ".rx") 0;
setAttr ($nurbsPlane1[0] + ".ry") 0;
setAttr ($nurbsPlane1[0] + ".rz") 0;

// now make some clusters for the ends of the joints
select -r ($nurbsPlane1[0] + ".cv[0][0:3]");
string $origCluster1[] =`cluster -en 1`;
parent ($origCluster1[0] + "Handle") $sel[0];
setAttr ($origCluster1[0] + "Handle.visibility") 0;

select -r ($nurbsPlane1[0] + ".cv[3][0:3]");
string $insertCluster1[] =`cluster -en 1`;
parent ($insertCluster1[0] + "Handle") $sel[1];
setAttr ($insertCluster1[0] + "Handle.visibility") 0;


// create two circles as controllers for the clusters
string $controller1[] =`circle -c 0 0 0 -nr 1 0 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;
string $controller2[] =`circle -c 0 0 0 -nr 1 0 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;

parent $controller1[0] $controller2[0] $sel[0];

setAttr ($controller1[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.33333);
setAttr ($controller1[0] + ".ty") 0;
setAttr ($controller1[0] + ".tz") 0;
setAttr ($controller1[0] + ".rx") 0;
setAttr ($controller1[0] + ".ry") 0;
setAttr ($controller1[0] + ".rz") 0;

setAttr ($controller2[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.66667);
setAttr ($controller2[0] + ".ty") 0;
setAttr ($controller2[0] + ".tz") 0;
setAttr ($controller2[0] + ".rx") 0;
setAttr ($controller2[0] + ".ry") 0;
setAttr ($controller2[0] + ".rz") 0;

// zero the transforms of the controller circles
select -r $controller1[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
select -r $controller2[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;


setAttr -lock false -keyable false ($controller1[0] + ".rx");
setAttr -lock true -keyable false ($controller1[0] + ".ry");
setAttr -lock true -keyable false ($controller1[0] + ".rz");
setAttr -lock true -keyable false ($controller1[0] + ".sx");
setAttr -lock true -keyable false ($controller1[0] + ".sy");
setAttr -lock true -keyable false ($controller1[0] + ".sz");

setAttr -lock false -keyable false ($controller2[0] + ".rx");
setAttr -lock true -keyable false ($controller2[0] + ".ry");
setAttr -lock true -keyable false ($controller2[0] + ".rz");
setAttr -lock true -keyable false ($controller2[0] + ".sx");
setAttr -lock true -keyable false ($controller2[0] + ".sy");
setAttr -lock true -keyable false ($controller2[0] + ".sz");

addAttr -ln twist -at double -min -360 -max 360 -dv 0 $controller1[0];
setAttr -e -keyable true ($controller1[0] + ".twist");

addAttr -ln twist -at double -min -360 -max 360 -dv 0 $controller2[0];
setAttr -e -keyable true ($controller2[0] + ".twist");

string $twistControllerA = $controller1[0] + ".rx = " + $controller1[0] + ".twist + (" + $sel[0] + ".rx * 0.333);" ;
string $twistControllerB = $controller2[0] + ".rx = " + $controller2[0] + ".twist + (" + $sel[1] + ".rx * 0.333);" ;

expression -s $twistControllerA -o $controller1[0] -ae 1 -uc all ;
expression -s $twistControllerB -o $controller2[0] -ae 1 -uc all ;



// make some clusters of the middle hulls
// parent the cluster Handles to the controller circles
select -r ($nurbsPlane1[0] + ".cv[1][0:3]");
string $controllerCluster1[] =`cluster -en 1`;
parent ($controllerCluster1[0] + "Handle") $controller1[0];
setAttr ($controllerCluster1[0] + "Handle.visibility") 0;


select -r ($nurbsPlane1[0] + ".cv[2][0:3]");
string $controllerCluster2[] =`cluster -en 1`;
parent ($controllerCluster2[0] + "Handle") $controller2[0];
setAttr ($controllerCluster2[0] + "Handle.visibility") 0;

rename $controller2[0] ($sel[0] + "stretchHandle2");
rename $controller1[0] ($sel[0] + "stretchHandle1");



// avoid double transform by moving the Nurbsplane to outside world
int $planeGroupExists = `objExists StretchyPLANES_DONT_TOUCH`;
if ($planeGroupExists == 1){

print ("stretchy Planes group already exists");

} else {

group -w -em -n "StretchyPLANES_DONT_TOUCH";


}
parent $nurbsPlane1[0] StretchyPLANES_DONT_TOUCH;


// =========== add the stretchy joints to the nurbs surface

float $jointIncrement = 1.00 / ($numJoints + 1);



// have a holder for all the rivet names
string $rivetNames[];
print ($rivetNames);

// add the first one NEAR the end of the nurbs plane
select -r ($nurbsPlane1[0] + ".uv[.001][0.5]");
$rivetNames[0] = `rivet`;


for ($i=1; $i <= $numJoints; $i++){
float $curRivU = $jointIncrement * $i ;
select -r ($nurbsPlane1[0] + ".uv[" + $curRivU + "][0.5]");
$rivetNames[$i] = `rivet`;

}

// add the first one NEAR the end of the nurbs plane
int $lastJt = $numJoints + 1;
select -r ($nurbsPlane1[0] + ".uv[.999][0.5]");
$rivetNames[$lastJt] = `rivet`;
string $stretchJointNames[];

for ($i=0; $i < size($rivetNames); $i++){
setAttr ($rivetNames[$i] + "Shape.lodVisibility") 0;
print ("\nmaking a stretchy joint for rivet " + $rivetNames[$i]);
string $curJnt =`joint -n ($sel[0] + "_stretch_" + $i) -p 0 0 0`;
delete `pointConstraint $rivetNames[$i] $curJnt`;
delete `orientConstraint $rivetNames[$i] $curJnt`;

parent $curJnt $rivetNames[$i];
select -r $curJnt;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

select -d;

}



// CLEANUP ======================================
delete $loc1[0];
delete $loc2[0];

setAttr ($nurbsPlane1[0] + ".template") 1;
displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 20 $nurbsPlane1[0];



int $rivetGroupExists = `objExists StretchyRIVETS_DONT_TOUCH`;
if ($rivetGroupExists == 1){

print ("stretchy Planes group already exists");

} else {

group -w -em -n "StretchyRIVETS_DONT_TOUCH";


}

parent $rivetNames StretchyRIVETS_DONT_TOUCH;

// rename them to prevent conflicts
for ($i=0; $i < size($rivetNames); $i++){

rename $rivetNames[$i] ("riv" + $sel[0] + $sel[1] + "_" + $i);

}

select -d;

}
// could be any number > 1
// ggmStretchyJoints (3);
ggmStretchyJoints (2);
 
Old 05 May 2006   #4
I think it was just variable scope. I just rearranged some of the brackets and indented the code to make it clearer which code is inside which bloc. Seems to be working now. Nice script.

Though I wonder how it would react with a different joint orientation....

// ================================================== ========================
// ggmStretchyJoints.mel
// 2005 Geordie Martinez
// Just give me credit for it, pal. That's all I ask.
//
// DESCRIPTION: Builds stretchy joints between two joints
// in a chain.
//
// NOTES: You're creating stretchy joints
// so you should only do this between two inline joints, not
// between the first and third or forth in an IK chain, but
// between EVERY joint in an IK chain.
// MUST have rivet.mel installed from highend3D.com
//
// VERSION 1.0
//
//
// SELECT the ORIGIN JOINT and SHIFT SELECT THE INSERTION JOINT
// Enter the number of joints you want IN BETWEEN the two existing joints
// I've defaulted it to 2 joints, but it could be any number.
// ================================================== ========================

global proc ggmStretchyJoints(int $numJoints)
{
if ($numJoints < 1)
{
error ("you need to have at least 1 joint in between these two joints");
return;
};


//select the start and end joints respectively
string $sel[] = `ls -type joint -sl`;



// create a locator at Origin Joint
string $loc1[] = `spaceLocator -p 0 0 0`;
delete `pointConstraint $sel[0] $loc1[0]`;

// create a locator at Insertion Joint
string $loc2[] = `spaceLocator -p 0 0 0`;
delete `pointConstraint $sel[1] $loc2[0]`;

//now measure the distance between them with a distanceBetween node
// you'll use this to move the nurbs plane into the right spot
string $distance1 = `createNode distanceBetween`;
connectAttr ($loc1[0] + ".translate") ($distance1 + ".point1");
connectAttr ($loc2[0] + ".translate") ($distance1 + ".point2");

// create a nurbs plane of known proportions
string $nurbsPlane1[] =`nurbsPlane -p 0 0 0 -ax 0 1 0 -w 1 -lr 1 -d 3 -u 1 -v 1 -ch 0`;
subdivDisplaySmoothness -smoothness 3;
// parent it to the source joint so
// its rotate, translate all become those of origin joint
parent $nurbsPlane1[0] $sel[0];

// setting all the rotate and translate to zero moves it into the correct position
setAttr ($nurbsPlane1[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.5);
setAttr ( $nurbsPlane1[0] + ".sx") (`getAttr ($distance1 + ".distance")`);
setAttr ($nurbsPlane1[0] + ".ty") 0;
setAttr ($nurbsPlane1[0] + ".tz") 0;
setAttr ($nurbsPlane1[0] + ".rx") 0;
setAttr ($nurbsPlane1[0] + ".ry") 0;
setAttr ($nurbsPlane1[0] + ".rz") 0;

// now make some clusters for the ends of the joints
select -r ($nurbsPlane1[0] + ".cv[0][0:3]");
string $origCluster1[] =`cluster -en 1`;
parent ($origCluster1[0] + "Handle") $sel[0];
setAttr ($origCluster1[0] + "Handle.visibility") 0;

select -r ($nurbsPlane1[0] + ".cv[3][0:3]");
string $insertCluster1[] =`cluster -en 1`;
parent ($insertCluster1[0] + "Handle") $sel[1];
setAttr ($insertCluster1[0] + "Handle.visibility") 0;


// create two circles as controllers for the clusters
string $controller1[] =`circle -c 0 0 0 -nr 1 0 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;
string $controller2[] =`circle -c 0 0 0 -nr 1 0 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;

parent $controller1[0] $controller2[0] $sel[0];

setAttr ($controller1[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.33333);
setAttr ($controller1[0] + ".ty") 0;
setAttr ($controller1[0] + ".tz") 0;
setAttr ($controller1[0] + ".rx") 0;
setAttr ($controller1[0] + ".ry") 0;
setAttr ($controller1[0] + ".rz") 0;

setAttr ($controller2[0] + ".tx") (`getAttr ($distance1 + ".distance")` * 0.66667);
setAttr ($controller2[0] + ".ty") 0;
setAttr ($controller2[0] + ".tz") 0;
setAttr ($controller2[0] + ".rx") 0;
setAttr ($controller2[0] + ".ry") 0;
setAttr ($controller2[0] + ".rz") 0;

// zero the transforms of the controller circles
select -r $controller1[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
select -r $controller2[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;


setAttr -lock false -keyable false ($controller1[0] + ".rx");
setAttr -lock true -keyable false ($controller1[0] + ".ry");
setAttr -lock true -keyable false ($controller1[0] + ".rz");
setAttr -lock true -keyable false ($controller1[0] + ".sx");
setAttr -lock true -keyable false ($controller1[0] + ".sy");
setAttr -lock true -keyable false ($controller1[0] + ".sz");

setAttr -lock false -keyable false ($controller2[0] + ".rx");
setAttr -lock true -keyable false ($controller2[0] + ".ry");
setAttr -lock true -keyable false ($controller2[0] + ".rz");
setAttr -lock true -keyable false ($controller2[0] + ".sx");
setAttr -lock true -keyable false ($controller2[0] + ".sy");
setAttr -lock true -keyable false ($controller2[0] + ".sz");

addAttr -ln twist -at double -min -360 -max 360 -dv 0 $controller1[0];
setAttr -e -keyable true ($controller1[0] + ".twist");

addAttr -ln twist -at double -min -360 -max 360 -dv 0 $controller2[0];
setAttr -e -keyable true ($controller2[0] + ".twist");

string $twistControllerA = $controller1[0] + ".rx = " + $controller1[0] + ".twist + (" + $sel[0] + ".rx * 0.333);" ;
string $twistControllerB = $controller2[0] + ".rx = " + $controller2[0] + ".twist + (" + $sel[1] + ".rx * 0.333);" ;

expression -s $twistControllerA -o $controller1[0] -ae 1 -uc all ;
expression -s $twistControllerB -o $controller2[0] -ae 1 -uc all ;



// make some clusters of the middle hulls
// parent the cluster Handles to the controller circles
select -r ($nurbsPlane1[0] + ".cv[1][0:3]");
string $controllerCluster1[] =`cluster -en 1`;
parent ($controllerCluster1[0] + "Handle") $controller1[0];
setAttr ($controllerCluster1[0] + "Handle.visibility") 0;


select -r ($nurbsPlane1[0] + ".cv[2][0:3]");
string $controllerCluster2[] =`cluster -en 1`;
parent ($controllerCluster2[0] + "Handle") $controller2[0];
setAttr ($controllerCluster2[0] + "Handle.visibility") 0;

rename $controller2[0] ($sel[0] + "stretchHandle2");
rename $controller1[0] ($sel[0] + "stretchHandle1");



// avoid double transform by moving the Nurbsplane to outside world
int $planeGroupExists = `objExists StretchyPLANES_DONT_TOUCH`;
if ($planeGroupExists == 1)
{
print ("stretchy Planes group already exists");
}
else
{
group -w -em -n "StretchyPLANES_DONT_TOUCH";
};
parent $nurbsPlane1[0] StretchyPLANES_DONT_TOUCH;


// =========== add the stretchy joints to the nurbs surface

float $jointIncrement = 1.00 / ($numJoints + 1);



// have a holder for all the rivet names
string $rivetNames[];
print ($rivetNames);

// add the first one NEAR the end of the nurbs plane
select -r ($nurbsPlane1[0] + ".uv[.001][0.5]");
$rivetNames[0] = `rivet`;


for ($i=1; $i <= $numJoints; $i++)
{
float $curRivU = $jointIncrement * $i ;
select -r ($nurbsPlane1[0] + ".uv[" + $curRivU + "][0.5]");
$rivetNames[$i] = `rivet`;
};


// add the first one NEAR the end of the nurbs plane
int $lastJt = $numJoints + 1;
select -r ($nurbsPlane1[0] + ".uv[.999][0.5]");
$rivetNames[$lastJt] = `rivet`;
string $stretchJointNames[];

for ($i=0; $i < size($rivetNames); $i++)
{
setAttr ($rivetNames[$i] + "Shape.lodVisibility") 0;
print ("\nmaking a stretchy joint for rivet " + $rivetNames[$i]);
string $curJnt =`joint -n ($sel[0] + "_stretch_" + $i) -p 0 0 0`;
delete `pointConstraint $rivetNames[$i] $curJnt`;
delete `orientConstraint $rivetNames[$i] $curJnt`;

parent $curJnt $rivetNames[$i];
select -r $curJnt;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

select -d;
};




// CLEANUP ======================================
delete $loc1[0];
delete $loc2[0];

setAttr ($nurbsPlane1[0] + ".template") 1;
displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 20 $nurbsPlane1[0];



int $rivetGroupExists = `objExists StretchyRIVETS_DONT_TOUCH`;
if ($rivetGroupExists == 1)
{
print ("stretchy Planes group already exists");
}
else
{
group -w -em -n "StretchyRIVETS_DONT_TOUCH";
};
parent $rivetNames StretchyRIVETS_DONT_TOUCH;

// rename them to prevent conflicts
for ($i=0; $i < size($rivetNames); $i++)
{
rename $rivetNames[$i] ("riv" + $sel[0] + $sel[1] + "_" + $i);
};

select -d;

};
// could be any number > 1
// ggmStretchyJoints (3);
ggmStretchyJoints(2);

Last edited by isoparmB : 05 May 2006 at 01:43 PM.
 
Old 05 May 2006   #5
Hm. Indentation gone. Damnit.
 
Old 05 May 2006   #6
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



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 03:02 PM.


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