Nov 2010
1 / 3
Nov 2010
Nov 2010

Hi All,
I've wrotten a script which sets up a couple of controls for a camera so that I can animate camera shake by hand. It's pretty primitive but works fine. However - I've run into some trouble...I suspect this is down to how Maya's apparently inconsistant way of naming camera Shape nodes.

If a camera is called shotCamera then the shape node is called shotCamera1
However is a camera is called camera1 then the shape node is called cameraShape1

Does anyone know why Maya shifts the number to the end like this - or how to allow for it in a simple script such as the one below....

// get selected camera name and position

string $cN[];
$cN = ls -sl;
string $cameraName = $cN[0];
$cP = getAttr ( $cameraName + ".translate" );

// get target name and target position

string $targetName;
$targetName = ($cN[0] + "_aim");
$tP = getAttr ( $targetName + ".translate" );

// copy animation from target

copyKey -time ":" -float ":" -hierarchy none -controlPoints 0 -shape 1 { ($targetName + ".translateX"), ($targetName + ".translateY"), ($targetName + ".translateZ")};

// put camera and aim to setup positions

setAttr ( $targetName + ".translateX" ) 0;
setAttr ( $targetName + ".translateY" ) 0;
setAttr ( $targetName + ".translateZ" ) 0;

setAttr ( $cameraName + ".translateX" ) 0;
setAttr ( $cameraName + ".translateY" ) 0;
setAttr ( $cameraName + ".translateZ" ) 5;

setAttr ( $targetName + "Shape.visibility" ) 1;
select $targetName;

// set name for new target

string $newTarget;
$newTarget = ($cameraName + "_aimGroup");

group;
rename $newTarget ;
string $newTargetShape;
$newTargetShape = ( $cameraName + "Shape" );

createNode -n $newTargetShape -p $newTarget locator;

setAttr ( $newTargetShape +   ".localScaleX" ) 2;
setAttr ( $newTargetShape +   ".localScaleY" ) 2;
setAttr ( $newTargetShape +   ".localScaleZ" ) 2;

// hide the old aim
setAttr ( $targetName + ".visibility" ) 0;

// create circles
string $smallName;
$smallName = ( $cameraName + "_smallShake" );
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0 -s 8 -ch 1; objectMoveCommand;
rename $smallName;
DeleteHistory;

string $bigName;
$bigName = ( $cameraName + "_bigShake" );
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0 -s 8 -ch 1; objectMoveCommand;
rename $bigName;
scale -r 1.666875 1.666875 1.666875 ;
DeleteHistory;

// need to rotate circles to face camera

setAttr ( $bigName + ".rotateX" ) -90;
setAttr ( $smallName + ".rotateX" ) -90;

// parenting to new Target

parent $smallName $newTarget;
parent $bigName $newTarget;

// orienting shakers to camera

orientConstraint -mo -weight 1 $cameraName $smallName;
orientConstraint -mo -weight 1 $cameraName $bigName;
orientConstraint -mo -weight 1 $cameraName $newTarget;

// apply the final point constraint to the camera_aim

pointConstraint $bigName $smallName $targetName;

// move camera and aim group back to start positions

setAttr ( $cameraName + ".translateX" ) $cP[0];
setAttr ( $cameraName + ".translateY" ) $cP[1];
setAttr ( $cameraName + ".translateZ" ) $cP[2];

setAttr ( $newTarget + ".translateX" )  $tP[0];
setAttr ( $newTarget + ".translateY" )  $tP[1];
setAttr ( $newTarget + ".translateZ" )  $tP[2];

// change circle colours

 setAttr ( $bigName + "Shape.overrideEnabled" ) 1;
 setAttr ( $bigName + "Shape.overrideColor" ) 17;

 setAttr ( $smallName + "Shape.overrideEnabled") 1;
 setAttr ( $smallName + "Shape.overrideColor") 4;

 setAttr ( $newTarget + ".overrideEnabled") 1;
 setAttr ( $newTarget + ".overrideColor") 18;

// paste keys into new target

pasteKey -time 1 -float 1 -option insert -copies 1 -connect 1 -timeOffset 0 -floatOffset 0 -valueOffset 0 { $newTarget };

// paste keys into new target

pasteKey -time 1 -float 1 -option insert -copies 1 -connect 1 -timeOffset 0 -floatOffset 0 -valueOffset 0 { $newTarget };

  • created

    Nov '10
  • last reply

    Nov '10
  • 2

    replies

  • 3.1k

    views

  • 1

    user

Nothing says the name HAS to be something. Indeed nothing says a node that has a camera shape can not have many camera shapes in the same node. See maya tries to avoid name collsions so it tends to add numbers to things.

when you go and do:

group;
rename $newTarget;

you dont know if the groups name is $newTarget, it might be something else if maya detects a naming clash so you should ALLWAYS capture what maya set:

$newNameIs = `rename $newTarget`;

Same elsewhere!

$newTargetShape = ( $cameraName + "Shape" );

should look like:

$temp = `listRelatives -shapes $cameraName`;
$newTargetShape = $temp[0]; // it is possible for transforms to
//have many shapes, rare for normal users but it DOES HAPPEN.

Thats about it. Some pointers tough avoid:

string $newTarget;
$newTarget = ($cameraName + "_aimGroup");
 
group;
rename $newTarget ;

do instead:

$newTarget = `group -n ($cameraName + "_aimGroup") $targetName`;

Maya's apparently inconsistant way of naming camera Shape nodes

Not really, the general naming scheme is quite consistent. Maya just puts the number after the shape so:

cameraFoobar  gets a shape named cameraFoobarShape

BUT:

camera1 gets named cameraShape1 so maya thinks the last number is a separate entity of the name and just a identifier tahst to be postfixed.

Hi Jooja,
Thanks for taking the time to respond to my post. I'll definitely try that out.
Cheers!
SG