When I was in my rigging class we were having to maintain a folder hierarchy and go through complex file paths just to import our rigging controls in a script. I thought this was inefficient since if we were going to send off a script for someone else to use they would have to move all these files in the same places and it would be a mess if one thing moved. So to make matter easier I wanted to be able to select a curve shape I made and easily get the script to recreate it without having to import a file. This is what I came up with.
Show Code
/*****************************************************************
Get Command to Recreate Curve V4
Written By: Charles Kinter
Last Updated: 2/22/2016
Objective:
Create Curve Command to recreate curve based controllers
To use:
ck_getpoints(X);
x = 1 or 3 for 1 Linear or 3 Cubic
Note: Curve command will create curves with the name of the Curve shape:
To Do:
1. Create Ui
2. Add option to add to shelf
***********************************************************************/
proc ck_getpoints(int $mode)
{
string $sel[] = `ls -sl`;
int $p;
// Cycle Through objects
for($objects in $sel)
{
string $childshapes[] = `listRelatives -shapes $objects`;
int $cshapecnt = `size($childshapes)`;
print (“Code for object : ” + $objects + “\n”);
// Cycle Through Subshapes
for ($thing in $childshapes)
{
string $getattrcmd = ($thing + “.ep[*]”);
vector $points[] = `getAttr $getattrcmd`;
// Find how many spans (points) there are .
string $spanscmd = ($thing + “.spans”);
int $psize = size($points)-1;
//int $psize = `getAttr $spanscmd`;
// get the mode 1 Linear or 3 Cubic and crete initial command.
string $curvecmd = (“curve -d ” + $mode);
// Take each Point and add them to the command string.
for ($p=0; $p<=$psize;$p++) { $curvecmd = ($curvecmd+ ” -ep ” + $points[$p]); } // OUtput command string into the Script Editor $curvecmd = ($curvecmd+ ” -ep ” + $points[0]); $curvecmd = ($curvecmd + ” -name \”” + $thing + “\”\;”); print $curvecmd; print “\n”; } if ($cshapecnt > 1)
{
print “You need to select all shapes and the main transform node and run parent -r -s\;”;
}
//Break between Objects
print “Next Object \n”;
}
}
Hope this helps anyone out there who just needs to get the code for a curve. Everything is output in the Script editor. It can be used on multiple shapes at a time.
Charles
