scripting

PyMel Script – Create Shader from folder of textures.

This script was a request from Monica Cappiello. Setting up a shader network and all its connections can be tedious work. Especially when working with artists or students who are not following the correct prefix naming convention. What this script does is prompt you to select a folder of textures. Then if they are named correctly plug them into the correct connections on the shading group and apply the shader to the selected object. If they are not named correctly you are prompted for what channel it should be mapped to and applies the correct prefix to the filenames. After fixing the files it then does the same shader creation functionality. Currently it supports aiStandardSurface, Blinn, Phong, and Lambert.

To install:
1: Put instantShaderUI.py and instantShaderClass.py in your C:\Users\’user’\Documents\maya\scripts folder
2. Add new shelf item with the following script:
import instantShaderUI
iscWindow()
To use:
1. Select object to assign to if desired.
2. Select Shader from drop down and hit create.
3. Select folder of images for your shader (will be name of shader). Must be in ‘jpg’,’gif’,’png’,’tif’,’bmp’ formats.
4. If files are named with correct prefixes shader will be created.
If not you will be prompted to fix each prefix and then the shader will be created.
5. Your newly created shader will be selected, take a moment to verify settings and enjoy.

Download here:
instantShader.zip

UPDATE:
Added better UI.
instantShaderUI.zip

Posted by Charles in All posts, scripting, 7 comments

PyMel Script – Rotate Spherical and Cylindrical UV projections

This script was designed for Dustin Aber. In Maya there is the built in functionality to choose a projection plane for planer projections. However, when you select to do a spherical or cylindrical projection you cannot specify a starting projection direction and have to manually rotate it with manipulators every time. It is available in the attributes however. This script loads a ui exposing that functionality making it easier for artists to project UVs quickly on non-defaultly oriented objects.

rotProUI.py

To install:
Place rotProUI.py in your C:\Users\(your user)\Documents\maya\scripts folder or equivalent location in your PYTHONPATH.
Usage:
1. In script editor run (can be added to shelf):
import rotProUI
rotProUI()
2. Select Object or set of faces
3. Select projection type from the radio buttons
4. Select rotation type
5. Click project

Please let me know if you have any feedback in the comments section.

Posted by Charles in All posts, scripting, 1 comment

Mel Script – Rigging Controls Script

Taking my previous idea a step further I made a little UI and an easily expandable script to create any those curves positioned on the object. I added a transform node that mirrors the object selected so a parent constraint can be added from the controller with no offset. To use this run the code, select the object or joint, click the controller type, and whammoo controller ready to constrain without offset.

Show Code


global proc cak_cntsUI()
{
int $dev = 1;
if ($dev && `window -exists "cntsUI_win"`)
{
deleteUI -window "cntsUI_win";
}
if (!`window -exists "cntsUI_win"`)
{
window -title "ControlUI"
-resizeToFitChildren true
-width 100
"cntsUI_win";
columnLayout -adjustableColumn true "cnts_Column";
text "Click Button to spawn controler at selection with \nsame translation rotation as selected.\n If nothing is selected it will spawn at origin.";
separator;
gridLayout -numberOfRowsColumns 1 5
-cellWidthHeight 70 50
"cnts_Grid";
button -label "Translate"
-command ("cak_crtls(1)") -parent "cnts_Grid" "trans_btn";
button -label "Translate\nRotate"
-command ("cak_crtls(2)") -parent "cnts_Grid" "TransRot_btn";
button -label "Nintendo"
-command ("cak_crtls(3)") -parent "cnts_Grid" "nintendo_btn";
button -label "Half\nRotate\nZ"
-command ("cak_crtls(4)") -parent "cnts_Grid" "hRotZ_btn";
button -label "Rotate\nZ"
-command ("cak_crtls(5)") -parent "cnts_Grid" "RotZ_btn";
button -label "Half\nRotate\nX"
-command ("cak_crtls(6)") -parent "cnts_Grid" "hRotX_btn";
button -label "Rotate\nX"
-command ("cak_crtls(7)") -parent "cnts_Grid" "RotX_btn";
button -label "Half\nRotate\nY"
-command ("cak_crtls(8)") -parent "cnts_Grid" "hRotY_btn";
button -label "Rotate\nY"
-command ("cak_crtls(9)") -parent "cnts_Grid" "RotY_btn";
button -label "Pole"
-command ("cak_crtls(10)") -parent "cnts_Grid" "pole_btn";
//add new controls above this line

setParent..;
}
showWindow "cntsUI_win";
}
cak_cntsUI();

proc cak_crtls(int $choice)
{

string $selLocAlign[] = `ls -sl`;
string $name ="";
string $ident = "";
string $shape = "";

switch($choice)
{
case 1:
$shape = "-d 1 -ep -1 0 -1 -ep -1 0 -5 -ep -2 0 -5 -ep 0 0 -8 -ep 2 0 -5 -ep 1 0 -5 -ep 1 0 -1 -ep 5 0 -1 -ep 5 0 -2 -ep 8 0 0 -ep 5 0 2 -ep 5 0 1 -ep 1 0 1 -ep 1 0 5 -ep 2 0 5 -ep 0 0 8 -ep -2 0 5 -ep -1 0 5 -ep -1 0 1 -ep -5 0 1 -ep -5 0 2 -ep -8 0 0 -ep -5 0 -2 -ep -5 0 -1 -ep -1 0 -1";
$ident = "trans";
break;

case 2:
$shape = "-d 3 -ep -3.869373271 -6.123233991e-017 0.9999999993 -ep -2.828427125 -1.731912112e-016 2.828427125 -ep -0.9999999993 -2.369307796e-016 3.869373271 -ep -0.9999999993 -2.369307796e-016 3.869373271 -ep -0.9999999993 -2.369307796e-016 3.869373271 -ep -1 0 5 -ep -1 0 5 -ep -1 0 5 -ep -2 0 5 -ep -2 0 5 -ep -2 0 5 -ep 0 0 8 -ep 0 0 8 -ep 0 0 8 -ep 2 0 5 -ep 2 0 5 -ep 2 0 5 -ep 1 0 5 -ep 1 0 5 -ep 1 0 5 -ep 1 0 3.86937328 -ep 1 0 3.86937328 -ep 1 0 3.86937328 -ep 2.828427125 -1.731912112e-016 2.828427125 -ep 3.869373271 -6.123233991e-017 0.9999999993 -ep 3.869373271 -6.123233991e-017 0.9999999993 -ep 3.869373271 -6.123233991e-017 0.9999999993 -ep 5 0 1 -ep 5 0 1 -ep 5 0 1 -ep 5 0 2 -ep 5 0 2 -ep 5 0 2 -ep 8 0 0 -ep 8 0 0 -ep 8 0 0 -ep 5 0 -2 -ep 5 0 -2 -ep 5 0 -2 -ep 5 0 -1 -ep 5 0 -1 -ep 5 0 -1 -ep 3.869373272 0 -1 -ep 3.869373272 0 -1 -ep 3.869373272 0 -1 -ep 2.828427125 1.731912112e-016 -2.828427125 -ep 0.9999999993 2.369307796e-016 -3.869373271 -ep 0.9999999993 2.369307796e-016 -3.869373271 -ep 0.9999999993 2.369307796e-016 -3.869373271 -ep 1 0 -5 -ep 1 0 -5 -ep 1 0 -5 -ep 2 0 -5 -ep 2 0 -5 -ep 2 0 -5 -ep 0 0 -8 -ep 0 0 -8 -ep 0 0 -8 -ep -2 0 -5 -ep -2 0 -5 -ep -2 0 -5 -ep -1 0 -5 -ep -1 0 -5 -ep -1 0 -5 -ep -1 0 -3.869373271 -ep -1 0 -3.869373271 -ep -1 0 -3.869373271 -ep -2.828427125 1.731912112e-016 -2.828427125 -ep -3.869373271 6.123233991e-017 -0.9999999993 -ep -3.869373271 6.123233991e-017 -0.9999999993 -ep -3.869373271 6.123233991e-017 -0.9999999993 -ep -5 0 -1 -ep -5 0 -1 -ep -5 0 -1 -ep -5 0 -2 -ep -5 0 -2 -ep -5 0 -2 -ep -8 0 0 -ep -8 0 0 -ep -8 0 0 -ep -5 0 2 -ep -5 0 2 -ep -5 0 2 -ep -5 0 1 -ep -5 0 1 -ep -5 0 1 -ep -3.869373271 -6.123233991e-017 0.9999999993";
$ident = "transRot";
break;

case 3:
$shape = "-d 1 -ep -3.86937328 0 1 -ep -1 0 1 -ep -1 0 1 -ep -1 0 1 -ep -1 0 3.86937328 -ep -1 0 3.86937328 -ep -1 0 3.86937328 -ep -3.774758284e-015 -2.449293598e-016 4 -ep 0.9999999993 -2.369307796e-016 3.869373271 -ep 0.9999999993 -2.369307796e-016 3.869373271 -ep 0.9999999993 -2.369307796e-016 3.869373271 -ep 1 0 1 -ep 1 0 1 -ep 1 0 1 -ep 3.86937328 0 1 -ep 3.86937328 0 1 -ep 3.86937328 0 1 -ep 4 -3.512896219e-031 5.828670879e-015 -ep 3.869373271 6.123233991e-017 -0.9999999993 -ep 3.869373271 6.123233991e-017 -0.9999999993 -ep 3.869373271 6.123233991e-017 -0.9999999993 -ep 1 0 -1 -ep 1 0 -1 -ep 1 0 -1 -ep 1 0 -3.869373272 -ep 1 0 -3.869373272 -ep 1 0 -3.869373272 -ep -3.219646771e-015 2.449293598e-016 -4 -ep -0.9999999999 2.369307796e-016 -3.869373271 -ep -0.9999999999 2.369307796e-016 -3.869373271 -ep -0.9999999999 2.369307796e-016 -3.869373271 -ep -1 0 -1 -ep -1 0 -1 -ep -1 0 -1 -ep -3.86937328 0 -1 -ep -3.86937328 0 -1 -ep -3.86937328 0 -1 -ep -4 5.854827031e-032 -8.881784197e-016 -ep -3.86937328 0 1";
$ident = "nin";
break;

case 4:
$shape = "-d 3 -ep 4 -1.567223571e-008 2.520287719e-024 -ep 2.828427125 -2.828427125 4.548457722e-016 -ep -1.221245327e-015 -4 6.432490599e-016 -ep -2.828427125 -2.828427125 4.548457722e-016 -ep -4 1.054711873e-015 -1.72563323e-031 -ep -4 1.054711873e-015 -1.72563323e-031 -ep -4 1.054711873e-015 -1.72563323e-031 -ep -4.518123667 0 0 -ep -4.518123667 0 0 -ep -4.518123667 0 0 -ep -3.959180814 0.5589428529 -1.241102449e-016 -ep -3.959180814 0.5589428529 -1.241102449e-016 -ep -3.959180814 0.5589428529 -1.241102449e-016 -ep -3.518123667 1 -2.220446049e-016 -ep -3.518123667 1 -2.220446049e-016 -ep -3.518123667 1 -2.220446049e-016 -ep -2.96519223 0.447068563 -9.926916245e-017 -ep -2.96519223 0.447068563 -9.926916245e-017 -ep -2.96519223 0.447068563 -9.926916245e-017 -ep -2.518123667 0 0 -ep -2.518123667 0 0 -ep -2.518123667 0 0 -ep -2.999999999 0 0 -ep -2.999999999 0 0 -ep -2.999999999 0 0 -ep -2.121320344 -2.121320344 3.411343292e-016 -ep -8.881784197e-016 -3 4.824367949e-016 -ep 2.121320344 -2.121320344 3.411343292e-016 -ep 3 -1.498801083e-015 2.43437545e-031 -ep 3 -1.498801083e-015 2.43437545e-031 -ep 3 -1.498801083e-015 2.43437545e-031 -ep 4 -1.567223571e-008 2.520287719e-024";
$ident = "hRotZ";
break;

case 5:
$shape = "-d 3 -ep -2.957326541 1.33226763e-015 -2.465190329e-031 -ep -2.078646885 -2.121320344 3.411343292e-016 -ep 0.04267345858 -3 4.824367949e-016 -ep 2.163993802 -2.121320344 3.411343292e-016 -ep 3.042673459 -1.054711873e-015 1.479114197e-031 -ep 2.163993802 2.121320344 -3.411343292e-016 -ep 0.04267345858 3 -4.824367949e-016 -ep -2.078646885 2.121320344 -3.411343292e-016 -ep -2.517095075 1.559768533 -2.508299106e-016 -ep -2.517095075 1.559768533 -2.508299106e-016 -ep -2.517095075 1.559768533 -2.508299106e-016 -ep -3.239604137 2.282277595 -5.06767427e-016 -ep -3.239604137 2.282277595 -5.06767427e-016 -ep -3.239604137 2.282277595 -5.06767427e-016 -ep -2.785753666 2.828427125 -4.548457722e-016 -ep 0.04267345858 4 -6.432490599e-016 -ep 2.871100583 2.828427125 -4.548457722e-016 -ep 4.042673459 -1.443289932e-015 1.972152263e-031 -ep 2.871100583 -2.828427125 4.548457722e-016 -ep 0.04267345858 -4 6.432490599e-016 -ep -2.785753666 -2.828427125 4.548457722e-016 -ep -3.957326541 1.498801083e-015 -2.958228395e-031 -ep -3.957326541 1.498801083e-015 -2.958228395e-031 -ep -3.957326541 1.498801083e-015 -2.958228395e-031 -ep -4.475450209 4.440892099e-016 -9.860761315e-032 -ep -4.475450209 4.440892099e-016 -9.860761315e-032 -ep -4.475450209 4.440892099e-016 -9.860761315e-032 -ep -3.916507356 0.5589428529 -1.241102449e-016 -ep -3.916507356 0.5589428529 -1.241102449e-016 -ep -3.916507356 0.5589428529 -1.241102449e-016 -ep -3.475450209 1 -2.220446049e-016 -ep -3.475450209 1 -2.220446049e-016 -ep -3.475450209 1 -2.220446049e-016 -ep -2.922518772 0.447068563 -9.926916245e-017 -ep -2.922518772 0.447068563 -9.926916245e-017 -ep -2.922518772 0.447068563 -9.926916245e-017 -ep -2.475450209 4.440892099e-016 -9.860761315e-032 -ep -2.475450209 4.440892099e-016 -9.860761315e-032 -ep -2.475450209 4.440892099e-016 -9.860761315e-032 -ep -2.957326541 1.33226763e-015 -2.465190329e-031";
$ident = "RotZ";
break;

case 6:
$shape = "-d 3 -ep 0 4 1.567223571e-008 -ep 0 2.828427125 2.828427125 -ep 0 -1.221245327e-015 4 -ep 0 -2.828427125 2.828427125 -ep 0 -4 -1.054711873e-015 -ep 0 -4 -1.054711873e-015 -ep 0 -4 -1.054711873e-015 -ep 0 -4.518123667 0 -ep 0 -4.518123667 0 -ep 0 -4.518123667 0 -ep 0 -3.959180814 -0.5589428529 -ep 0 -3.959180814 -0.5589428529 -ep 0 -3.959180814 -0.5589428529 -ep 0 -3.518123667 -1 -ep 0 -3.518123667 -1 -ep 0 -3.518123667 -1 -ep 0 -2.96519223 -0.447068563 -ep 0 -2.96519223 -0.447068563 -ep 0 -2.96519223 -0.447068563 -ep 0 -2.518123667 0 -ep 0 -2.518123667 0 -ep 0 -2.518123667 0 -ep 0 -2.999999999 0 -ep 0 -2.999999999 0 -ep 0 -2.999999999 0 -ep 0 -2.121320344 2.121320344 -ep 0 -8.881784197e-016 3 -ep 0 2.121320344 2.121320344 -ep 0 3 1.498801083e-015 -ep 0 3 1.498801083e-015 -ep 0 3 1.498801083e-015 -ep 0 4 1.567223571e-008";
$ident = "hRotX";
break;

case 7:
$shape = "-d 3 -ep -8.881784197e-016 -2.957326541 -1.33226763e-015 -ep -7.401486831e-016 -2.078646885 2.121320344 -ep -2.465190329e-032 0.04267345858 3 -ep 7.401486831e-016 2.163993802 2.121320344 -ep 7.401486831e-016 3.042673459 1.054711873e-015 -ep 1.480297366e-016 2.163993802 -2.121320344 -ep -1.927872545e-016 0.04267345858 -3 -ep -8.609285703e-016 -2.078646885 -2.121320344 -ep -8.881784197e-016 -2.517095075 -1.559768533 -ep -8.881784197e-016 -2.517095075 -1.559768533 -ep -8.881784197e-016 -2.517095075 -1.559768533 -ep -8.881784197e-016 -3.239604137 -2.282277595 -ep -8.881784197e-016 -3.239604137 -2.282277595 -ep -8.881784197e-016 -3.239604137 -2.282277595 -ep -8.714635813e-016 -2.785753666 -2.828427125 -ep -1.994355747e-016 0.04267345858 -4 -ep 1.480297366e-016 2.871100583 -2.828427125 -ep 7.401486831e-016 4.042673459 1.443289932e-015 -ep 7.401486831e-016 2.871100583 2.828427125 -ep 2.465190329e-032 0.04267345858 4 -ep -7.401486831e-016 -2.785753666 2.828427125 -ep -8.881784197e-016 -3.957326541 -1.498801083e-015 -ep -8.881784197e-016 -3.957326541 -1.498801083e-015 -ep -8.881784197e-016 -3.957326541 -1.498801083e-015 -ep -8.881784197e-016 -4.475450209 -4.440892099e-016 -ep -8.881784197e-016 -4.475450209 -4.440892099e-016 -ep -8.881784197e-016 -4.475450209 -4.440892099e-016 -ep -8.881784197e-016 -3.916507356 -0.5589428529 -ep -8.881784197e-016 -3.916507356 -0.5589428529 -ep -8.881784197e-016 -3.916507356 -0.5589428529 -ep -8.881784197e-016 -3.475450209 -1 -ep -8.881784197e-016 -3.475450209 -1 -ep -8.881784197e-016 -3.475450209 -1 -ep -8.881784197e-016 -2.922518772 -0.447068563 -ep -8.881784197e-016 -2.922518772 -0.447068563 -ep -8.881784197e-016 -2.922518772 -0.447068563 -ep -8.881784197e-016 -2.475450209 -4.440892099e-016 -ep -8.881784197e-016 -2.475450209 -4.440892099e-016 -ep -8.881784197e-016 -2.475450209 -4.440892099e-016 -ep -8.881784197e-016 -2.957326541 -1.33226763e-015";
$ident = "RotX";
break;

case 8:
$shape = "-d 3 -ep 4 -9.596476685e-025 1.567223571e-008 -ep 2.828427125 -1.731912112e-016 2.828427125 -ep -3.330669074e-016 -2.449293598e-016 4 -ep -2.828427125 -1.731912112e-016 2.828427125 -ep -4 6.162975822e-032 -1.054711873e-015 -ep -4 6.162975822e-032 -1.054711873e-015 -ep -4 6.162975822e-032 -1.054711873e-015 -ep -4.518123667 0 0 -ep -4.518123667 0 0 -ep -4.518123667 0 0 -ep -3.959180814 0 -0.5589428529 -ep -3.959180814 0 -0.5589428529 -ep -3.959180814 0 -0.5589428529 -ep -3.518123667 0 -1 -ep -3.518123667 0 -1 -ep -3.518123667 0 -1 -ep -2.96519223 0 -0.447068563 -ep -2.96519223 0 -0.447068563 -ep -2.96519223 0 -0.447068563 -ep -2.518123667 0 0 -ep -2.518123667 0 0 -ep -2.518123667 0 0 -ep -2.999999999 0 0 -ep -2.999999999 0 0 -ep -2.999999999 0 0 -ep -2.121320344 -1.298934084e-016 2.121320344 -ep -2.386979503e-015 -1.836970199e-016 3 -ep 2.121320344 -1.298934084e-016 2.121320344 -ep 3 -8.936314942e-032 1.498801083e-015 -ep 3 -8.936314942e-032 1.498801083e-015 -ep 3 -8.936314942e-032 1.498801083e-015 -ep 4 -9.596476685e-025 1.567223571e-008";
$ident = "hRotY";
break;

case 9:
$shape = "-d 3 -ep -2.957326541 7.395570986e-032 -1.33226763e-015 -ep -2.078646885 -1.298934084e-016 2.121320344 -ep 0.04267345858 -1.836970199e-016 3 -ep 2.163993802 -1.298934084e-016 2.121320344 -ep 3.042673459 -6.471124613e-032 1.054711873e-015 -ep 2.163993802 1.298934084e-016 -2.121320344 -ep 0.04267345858 1.836970199e-016 -3 -ep -2.078646885 1.298934084e-016 -2.121320344 -ep -2.517095075 9.550827707e-017 -1.559768533 -ep -2.517095075 9.550827707e-017 -1.559768533 -ep -2.517095075 9.550827707e-017 -1.559768533 -ep -3.239604137 2.465190329e-032 -2.282277595 -ep -3.239604137 2.465190329e-032 -2.282277595 -ep -3.239604137 2.465190329e-032 -2.282277595 -ep -2.785753666 1.731912112e-016 -2.828427125 -ep 0.04267345858 2.449293598e-016 -4 -ep 2.871100583 1.731912112e-016 -2.828427125 -ep 4.042673459 -9.860761315e-032 1.443289932e-015 -ep 2.871100583 -1.731912112e-016 2.828427125 -ep 0.04267345858 -2.449293598e-016 4 -ep -2.785753666 -1.731912112e-016 2.828427125 -ep -3.957326541 8.628166151e-032 -1.498801083e-015 -ep -3.957326541 8.628166151e-032 -1.498801083e-015 -ep -3.957326541 8.628166151e-032 -1.498801083e-015 -ep -4.475450209 2.465190329e-032 -4.440892099e-016 -ep -4.475450209 2.465190329e-032 -4.440892099e-016 -ep -4.475450209 2.465190329e-032 -4.440892099e-016 -ep -3.916507356 2.465190329e-032 -0.5589428529 -ep -3.916507356 2.465190329e-032 -0.5589428529 -ep -3.916507356 2.465190329e-032 -0.5589428529 -ep -3.475450209 2.465190329e-032 -1 -ep -3.475450209 2.465190329e-032 -1 -ep -3.475450209 2.465190329e-032 -1 -ep -2.922518772 2.465190329e-032 -0.447068563 -ep -2.922518772 2.465190329e-032 -0.447068563 -ep -2.922518772 2.465190329e-032 -0.447068563 -ep -2.475450209 2.465190329e-032 -4.440892099e-016 -ep -2.475450209 2.465190329e-032 -4.440892099e-016 -ep -2.475450209 2.465190329e-032 -4.440892099e-016 -ep -2.957326541 7.395570986e-032 -1.33226763e-015";
$ident = "RotY";
break;

case 10:
$shape = "-d 1 -ep 1.311341578e-007 -1 -1 -ep 0 1 0 -ep -1 -1 -8.742277657e-008 -ep -4.371138829e-008 -1 1 -ep 0 1 0 -ep 1 -1 0 -ep 1.311341578e-007 -1 -1 -ep -4.371138829e-008 -1 1 -ep 1 -1 0 -ep -1 -1 -8.742277657e-008 -ep 1.311341578e-007 -1 -1";
$ident = "pole";
break;
//add new cases above this line

}

if(`objExists $selLocAlign[0]`)
{
for ($allNodes in $selLocAlign)
{
$name = ("anim_" + $selLocAlign[0]+ "_" + $ident + "_ctrl");
string $lc = `eval curve $shape -name $name`;
string $trans = `createNode "transform" -p $selLocAlign[0] -n ("Anim_" +$selLocAlign[0] + "_neutral")`;
parent -w $trans;
parent -r $name $trans;
setAttr ($lc + ".overrideEnabled") 1;
setAttr ($lc + ".overrideColor") 17;
}
select -r $selLocAlign[0];
}
else
{
$name = ("anim_" + $ident + "_ctrl");
string $orgctl = `eval curve $shape -name $name`;
setAttr ($orgctl + ".overrideEnabled") 1;
setAttr ($orgctl + ".overrideColor") 17;
select -r $orgctl;

}

};

 

You can add more controls by adding a new case in this format to the cak_crtls procedure:

case casenumber:
$shape = "curve command flags"
$ident = "controlname";
break;

The case number is the next number.
In the $shape field you add in every flag that follows the “curve” command to create the desired shape
The $ident field is the shapes name.

Then to add it to the ui you add this to the cak_cntsUI procedure:

button -label "controlname"
-command ("cak_crtls(casenumber)") -parent "cnts_Grid" "controlname_btn";

Hope you enjoy this script.

Posted by Charles in All posts, scripting, 0 comments

Mel Script – Getting the points of a Curve and creating a MEL command to recreate it

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

Posted by Charles in All posts, scripting, 0 comments