Skip to content

Instantly share code, notes, and snippets.

@JustinPedersen
Created July 28, 2017 12:28
Show Gist options
  • Save JustinPedersen/cd6cc1aa17903afed76a99bad8851325 to your computer and use it in GitHub Desktop.
Save JustinPedersen/cd6cc1aa17903afed76a99bad8851325 to your computer and use it in GitHub Desktop.
// NOTES
// add set all to default
// ============================================================================================================== //
/* ============================================== CREATING WINDOW =============================================== */
// ============================================================================================================== //
if (`window -ex AttributeMaster`)
deleteUI AttributeMaster;
window -wh 300 700 -s 0 AttributeMaster;
frameLayout
-bv 1
-bgc 0.6 0 0.23
-l "Add Attribute";
string $AttrName = `textField -tx "Attr_Name" UserAttrName`;
string $AttrNiceName = `textField -tx "Nice Name" UserAttrNiceName`;
rowColumnLayout -nc 3 -cw 1 60 -cw 2 60 -cw 3 60 -h 15;
string $AttrType = `radioCollection`;
string $Float, $Int, $Bool;
$Float = `radioButton -l "Float"`;
$Int = `radioButton -l "Int"`;
$Bool = `radioButton -l "Bool"`;
radioCollection -e -sl $Float $AttrType;
setParent ..;
button -w 200 -h 30 -l "ADD" -al "center";
setParent ..;
frameLayout
-bv 1
-bgc 0 0.5 0
-l "Edit Attribute";
columnLayout;
separator;
button -l "Delete Attribute" -w 200 -h 50 -c DeleteAttr;
separator;
rowColumnLayout -nc 2 -cw 1 100 -cw 2 100;
separator;separator;
button -h 30 -l "Move UP" -c ("cAE_moveAttrs(0)") -ann ("Slide selected channelBox attributes up.");
button -h 30 -l "Move Down" -c ("cAE_moveAttrs(1)") -ann ("Slide selected channelBox attributes down.");
separator;separator;
button -h 30 -l "Set Max" -c SetMax;
button -h 30 -l "Set Min" -c SetMin;
setParent ..;
setParent ..;
frameLayout
-bv 1
-bgc 0 0.25 0.5
-l "Utility";
columnLayout;
button -w 200 -l "Standard Divider" -c StandardDivider;
string $CutomHeadingTXTfld = `textField -w 200 -tx "Custom_Heading" UserCustHeadingTXT`;
button -w 200 -l "Custom Divider" -c "MakeCustomHeading($heading);";
rowColumnLayout -nc 2 -cw 1 100 -cw 2 100;
button -w 100 -l "Unlock All" -c msAttrUnlockUnhide_all;
button -w 100 -l "ROO" -c ROO;
setParent ..;
setParent ..;
showWindow AttributeMaster;
// ============================================================================================================== //
/* ============================================ Button Procs ==================================================== */
// ============================================================================================================== //
/* ============================================ Edit ATTR Procs ================================================= */
proc DeleteAttr(){
string $CBAttrs[] = `channelBox -q -sma mainChannelBox` ;
string $CBObjs[] = `channelBox -q -mol mainChannelBox` ;
print $CBAttrs;
print $CBObjs;
for ($ATTR in $CBAttrs){
CBunlockAttr ($CBObjs[0] + "." + $ATTR);
deleteAttr -attribute $ATTR;
}
}
proc SetMax(){
string $CBAttrs[] = `channelBox -q -sma mainChannelBox` ;
string $CBObjs[] = `channelBox -q -mol mainChannelBox` ;
float $MaxVal = `getAttr ($CBObjs[0] + "." + $CBAttrs[0])`;
// if the attr is user defined set the max, if it isnt continue.
int $NumUD = size($userDefined);
for($attr in $CBAttrs){
addAttr -e -hxv 1 -max ($MaxVal) ($CBObjs[0] + "." + $attr);
print ("Set Maximum Value of " + $CBObjs[0] + " to " + $MaxVal);
}
}
proc SetMin(){
string $CBAttrs[] = `channelBox -q -sma mainChannelBox` ;
string $CBObjs[] = `channelBox -q -mol mainChannelBox` ;
float $MinVal = `getAttr ($CBObjs[0] + "." + $CBAttrs[0])`;
// if the attr is user defined set the max, if it isnt continue.
for($attr in $CBAttrs){
addAttr -e -hnv 1 -min ($MinVal) ($CBObjs[0] + "." + $attr);
print ("Set Maximum Value of " + $CBObjs[0] + " to " + $MinVal);
}
}
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;
}
/* ============================================ UTILITY Procs =================================================== */
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);
}
}
}
proc MakeCustomHeading(string $heading){
string $headingName = `textField -query -text UserCustHeadingTXT`;
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 ROO(){
string $Selection[] = `ls -sl`;
for ($Var in $Selection){
addAttr -ln "rotate_order" -at "enum" -en "xyz:yzx:zxy:xzy:yxz:zyx:" $Var;
setAttr -keyable 1 ($Var + ".rotate_order");
connectAttr -f ($Var + ".rotate_order") ($Var + ".rotateOrder");
}
}
global proc msAttrUnlockUnhide_all()
{
string $selectedObj[] = `ls -sl`;
for($obj in $selectedObj)
{
string $attrList[] = `listAttr -v -l`; // Get attributes that are visibily locked
for($attribute in $attrList)
{
setAttr -k 1 -l 0 ($obj + "." + $attribute); // Unhide and unlock attribute
}
/*
Set Default trans, rot, and scale attribute to unhidden and unlocked
*/
setAttr -k 1 ($obj + ".tx");
setAttr -l 0 ($obj + ".tx");
setAttr -k 1 ($obj + ".ty");
setAttr -l 0 ($obj + ".ty");
setAttr -k 1 ($obj + ".tz");
setAttr -l 0 ($obj + ".tz");
setAttr -k 1 ($obj + ".sx");
setAttr -l 0 ($obj + ".sx");
setAttr -k 1 ($obj + ".sy");
setAttr -l 0 ($obj + ".sy");
setAttr -k 1 ($obj + ".sz");
setAttr -l 0 ($obj + ".sz");
setAttr -k 1 ($obj + ".rx");
setAttr -l 0 ($obj + ".rx");
setAttr -k 1 ($obj + ".ry");
setAttr -l 0 ($obj + ".ry");
setAttr -k 1 ($obj + ".rz");
setAttr -l 0 ($obj + ".rz");
clear $attrList;
$attrList = `listAttr -ud`; // Get attributes that are userdefined, hidden or not
for($attribute in $attrList)
{
setAttr -k 1 -l 0 ($obj + "." + $attribute); // Unhide and unlock attribute
}
clear $attrList;
}
clear $selectedObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment