Skip to content

Instantly share code, notes, and snippets.

@JustinPedersen
Last active July 23, 2017 20:24
Show Gist options
  • Save JustinPedersen/72425332376be460f89be3b5b056bff5 to your computer and use it in GitHub Desktop.
Save JustinPedersen/72425332376be460f89be3b5b056bff5 to your computer and use it in GitHub Desktop.
Channel Divider created by: Justin Pedersen For The animation school
/*
Channel Divider created by: Justin Pedersen For The animation school
justin@tcgcape.co.za
Ver: 001
Date: 7/12/2017
Maya ver: 2017 update 4
NOTE: REorder attrs section origionally
Michael B. Comet - comet@comet-cartoons.com
Copyright ©2004 Michael B. Comet - All Rights Reserved.
Then modified by me to work with current version of maya and integrated into this tool.
*/
string $heading = "heading";
if (`window -ex ChannelDivider`)
deleteUI ChannelDivider;
window -wh 200 200 -s 1 ChannelDivider;
frameLayout -l "TAS Channel Divider by: Sheep";
button -c StandardDivider -label "standard Divider" -bgc 0.8 1 8.0;
separator;
textField -tx $heading $heading;
button -c "MakeCustomHeading($heading);" -label "Make Custom Heading" -bgc 0.8 1 0.059;
setParent;
frameLayout -l "Attr Reorder";
rowColumnLayout -numberOfColumns 2 -columnWidth 1 100 -columnWidth 2 100;
button -l "Move UP" -c ("cAE_moveAttrs(0)") -ann ("Slide selected channelBox attributes up.");
button -l "Move Down" -c ("cAE_moveAttrs(1)") -ann ("Slide selected channelBox attributes down.");
showWindow ChannelDivider;
//================================================================================
proc MakeCustomHeading(string $heading){
string $headingName = `textField -query -text $heading`;
string $CustSelection[] = `ls -sl`;
$CustSelSize = size($CustSelection);
if($CustSelSize == 0){
warning "please Select at least one control";
}else{
for($CustAttr in $CustSelection){
if(catch(`addAttr -ln $headingName -at "enum" -en "----------:" $CustAttr`)){
warning "Name Must Be Unique";
}else{
setAttr -keyable true -lock true ($CustAttr + "." + $headingName);
}
}
}
}
//================================================================================
proc StandardDivider(){
string $Selection[] = `ls -sl`;
$selSize = size($Selection);
if($selSize == 0){
warning "please Select at least one control";
}else{
for ($Attrs in $Selection){
string $AtrEx[] = `listAttr - ud`;
$AttrNum = size($AtrEx);
float $num = $AttrNum;
string $AttrName = ("Divider" + $num);
addAttr -ln $AttrName -nn "__________" -at "double" $Attrs;
setAttr -keyable true -lock true ( $Attrs + "." + $AttrName);
}
}
}
//================================================================================
// --------------------------------------------------------------------------
/*
* cAE_moveAttrs() - Adjust attrs
*/
global proc cAE_moveAttrs(int $dir)
{
// find what's Locked in the User defined list.
string $UserDefAttrs[] = `listAttr -ud -locked` ;
string $cbObjs[] = `channelBox -q -mol mainChannelBox` ;
// Unlock it
for ($Attrs in $UserDefAttrs){
string $UnlockAttrs = `setAttr -lock false ($cbObjs[0] + "." + $Attrs)`;
}
// What objs and attrs are highlighted in the channel box?
string $cbObjs[] = `channelBox -q -mol mainChannelBox` ;
string $cbAttrs[] = `channelBox -q -sma mainChannelBox` ;
int $i;
string $obj ;
for ($obj in $cbObjs)
{
if ($dir == 0) // Work top to bottom if moving up
{
for ($i=0; $i < size($cbAttrs); ++$i)
cAE_moveAttr($obj, $cbAttrs[$i], $dir) ;
}
else if ($dir == 1) // Work bottom to top moving down
{
for ($i=size($cbAttrs)-1; $i >= 0; --$i)
cAE_moveAttr($obj, $cbAttrs[$i], $dir) ;
}
// Must do this or channel box won't refresh.
string $sel[] = `ls -sl -l`;
select -cl ;
refresh ;
select -r $sel ;
}
// Lock previously unlocked Attrs
for ($Attrs in $UserDefAttrs){
string $UnlockAttrs = `setAttr -lock true ($cbObjs[0] + "." + $Attrs)`;
}
}
// --------------------------------------------------------------------------
/*
* cAE_moveAttr() - Adjust one attr specified up or down.
* $dir: 0=up 1=down
*/
global proc cAE_moveAttr(string $obj, string $attr, int $dir)
{
string $udAttrs[] = `listAttr -ud $obj` ; // Get just user defined ones.
int $i ;
// First find out where in the order of all the user defined attrs this one is.
int $idx = -1 ;
for ($i=0; $i < size($udAttrs); ++$i)
{
if ($udAttrs[$i] == $attr)
{
$idx = $i;
break ;
}
}
// If we couldn't find it, it's not a ud, so ignore, we can't shift.
if ($idx < 0)
{
warning -sl 0 ("Can't shift "+$obj+"."+$attr+" it's not user defined.") ;
return ;
}
print ("// Shifting "+($dir==0 ? "Up" : "Down")+" "+$idx+".) "+$obj+"."+$attr+" //\n") ;
// Now shift as needed
if ($dir == 0 && $idx > 0)
{
cAE_dropToBottom($obj, $udAttrs[$idx]) ; // First this goes down
cAE_dropToBottom($obj, $udAttrs[$idx-1]) ; // Then the one above
// Then do the rest
for ($i=$idx+1; $i < size($udAttrs); ++$i)
{
cAE_dropToBottom($obj, $udAttrs[$i]) ;
}
}
else if ($dir == 1 && $idx < size($udAttrs)-1)
{
cAE_dropToBottom($obj, $udAttrs[$idx+1]) ; // First the one below goes down
cAE_dropToBottom($obj, $udAttrs[$idx]) ; // First this goes down
// Then do the rest
for ($i=$idx+2; $i < size($udAttrs); ++$i)
{
cAE_dropToBottom($obj, $udAttrs[$i]) ;
}
}
}
// --------------------------------------------------------------------------
global proc cAE_dropToBottom(string $obj, string $attr)
{
deleteAttr -attribute $attr $obj;
Undo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment