Script: Hide/Display Local Axis

Script: Hide/Display Local Axis

It can be a hassle to turn on/off the local axis of multiple objects simultaneously, the reason for this is that by default there’s no on and off option on “Display > Local Rotation Axis“, it’s just a toggle. This means that if you select a bunch of objects and toggle the local axis, the objects that already have the local axis visible will be hidden, while the rest of the selection’s local handles will be visible. This can be frustrating at times, especially if you have joints/objects that have the same position and orientation.

 

This is a really simple script, it basicly just adds the flag that defines on/off to the command that toggle’s the local axis. I’ve also added an option for it to go through the entire hierarchy, definitely a timesaver.

jh_dispLocalAxis (Hide/Display the local axis on multiple objects simultaneously)

//*************************************************************************************************************
// Title: jh_dispLocalAxis.mel
// Author: Jørn-Harald Paulsen
// Created: January 27, 2012
// Last Update: January 27, 2012
// Description: Utility to display or hide the local rotation axis of the selected object(s)
//*************************************************************************************************************
// MAIN WINDOW
//*************************************************************************************************************
global proc jh_dispLocalAxis()
{
//Delete window if it already exists
if (`window -q -ex jh_dispLocalAxis`) deleteUI jh_dispLocalAxis;

//Main Window
window -topEdge 30 -title “Display/Hide Local Axis”
-mxb false -s true -rtf false -mb false -mbv false -w 300 -h 440 jh_dispLocalAxis;

//Window content
columnLayout -adjustableColumn true;
separator -w 240 -h 20;
text -label “Utility to display or hide the local rotation axis of the selected object(s)” -fn boldLabelFont;
separator -w 240 -h 25;
button -label “Display Local Axis on selected object(s)” -c “jh_dispAxis 1 0”;
button -label “Hide Local Axis on selected object(s)” -c “jh_dispAxis 0 0” -bgc 0.23 0.23 0.23;
separator -w 240 -h 25;
button -label “Display Local Axis on selected object(s) (with hierarchy)” -c “jh_dispAxis 1 1”;
button -label “Hide Local Axis on selected object(s) (with hierarchy)” -c “jh_dispAxis 0 1” -bgc 0.23 0.23 0.23;
separator -w 240 -h 25;
window -e -w 300 -h 500 jh_dispLocalAxis;
showWindow jh_dispLocalAxis;
}

global proc jh_dispAxis(int $state, int $hierarchy)
{
//If (with hierarchy) was selected, select the hierarchy
if($hierarchy == 1) select -hi;
//Get the selected object(s)
string $selObj[] = `ls -sl`;
//For each object
for($sel in $selObj)
{
//If the attribute “displayLocalAxis” exist on the current object
if(`attributeExists “displayLocalAxis” $sel`)
{
//Sel the state of the local axis
setAttr ($sel + “.displayLocalAxis”) $state;
}
}
}

jh_dispLocalAxis;

Download Script

 

Script: Find Duplicate Names

Script: Find Duplicate Names

When dealing with rigs you often end up having a ton of nodes, and it’s easy to end up having several objects with the same name. You may think that Maya automaticly renames those objects for you, and it does, but only if the objects are in the same hierarchy. However, if you have the objects in separate hierarchies they can share the same name.

This isn’t really a problem in it self because Maya will just use longnames to distinguish them apart, but you may run into problems if you’re using scripts that doesn’t take longnames into consideration.

Example:

In the image above we have two objects named “pCube”. So what Maya does to distinguish them apart is to look at their parent, if the parent’s name is unique it will use that in the longname when dealing the objects. So if I were to select the pCube in root2, Maya would read it as “grp2|pcube”, and if both of the mid-groups was named “grp2” then maya would read the pCube as “root2|grp2|pCube”.

 

I’ve made a script that finds (and renames) all of the objects in the scene sharing the same name, the download link is at the bottom :)

jh_findDuplicateNames (Find and rename duplicate objects in the scene)

//*************************************************************************************************************
// Title: jh_findDuplicateNames.mel
// Author: Jørn-Harald Paulsen
// Created: May 24, 2012
// Last Update: May 24, 2012
// Description: Utility to find and rename objects with duplicate names in the scene
//*************************************************************************************************************
// MAIN WINDOW
//*************************************************************************************************************
global proc jh_findDuplicateNames()
{
//Delete window if it already exists
if (`window -q -ex jh_findDuplicateNames`) deleteUI jh_findDuplicateNames;

//Main Window
window -topEdge 30 -title “Find Duplicate Names”
-mxb false -s true -rtf false -mb false -mbv false -w 284 -h 194 jh_findDuplicateNames;

//Window content
columnLayout -adjustableColumn true;
text -label “\nUtility to find and rename duplicate names in the scene.”;
separator -w 240 -h 40;
button -label “Just select the objects with duplicate names” -c jh_findDuplicates;
separator -w 240 -h 30;
button -label “Select and rename objects with duplicate names” -c jh_renameDuplicates;
separator -w 240 -h 30;
window -e -w 284 -h 194 jh_findDuplicateNames;
showWindow jh_findDuplicateNames;
}

global proc jh_findDuplicates()
{
//Create a string-array to store the duplicates in
string $duplicateNames[];
//Get all of the transform-nodes in the scene
string $transformNodes[] = `ls -type transform`;

//Create a counter
int $counter = 0;
//For each object
for($node in $transformNodes)
{
//If it’s a duplicate object, put it in the variable for duplicates
if(`match “|” $node` == “|”)
{
$duplicateNames[$counter] = $node;
$counter = $counter + 1;
}
}

//Get the number of duplicate objects
int $numDuplicates = `size $duplicateNames`;
//Print information
print $duplicateNames;
print (“\nThere’s a total of ” + $numDuplicates + ” transform-nodes with the same name in the scene:\n”);
//Select the duplicate names
select -r $duplicateNames;
}

global proc jh_renameDuplicates()
{
//Create a string-array to store the duplicates in
string $duplicateNames[];
//Get all of the transform-nodes in the scene
string $transformNodes[] = `ls -type transform`;

//Create a counter
int $counter = 0;
//For each object
for($node in $transformNodes)
{
//If it’s a duplicate object, put it in the variable for duplicates
if(`match “|” $node` == “|”)
{
$duplicateNames[$counter] = $node;
$counter = $counter + 1;
}
}

//Reset the counter
$counter = 0;
//For each of the duplicate objects
for($duplicate in $duplicateNames)
{
//Tokenize the strings
string $nameBuffer[];
int $numTokens = `tokenize $duplicate “|” $nameBuffer`;
//For each of the tokens
for($a=0; $a < `size $nameBuffer`; $a++) { //Get the duplicates of the current token string $dupToken[] = `ls (“*” + $nameBuffer[$a])`; //Get the number of duplicates with the same name as tokenized int $sizeToken = `size $dupToken`; //If there’s more than one object if($sizeToken > 1)
{
//For each duplicate name
for($i=1; $i < $sizeToken; $i++)
{
$dupToken[$i] = `rename $dupToken[$i] ($nameBuffer[$a] + “_dup_” + $i)`;
$counter = $counter + 1;
}
}
}
}

//Print information
print (“\nA total of ” + $counter + ” transform-nodes was renamed\n”);
}

jh_findDuplicateNames;

Download Script