literature

Transform Control Script

Deviation Actions

LOckaduda's avatar
By
Published:
1.2K Views

Literature Text

global string $aTransX ="0.0";
global string $aTransY ="0.0";
global string $aTransZ ="0.0";
global string $floatFieldNameAtransX="";
global string $floatFieldNameAtransY="";
global string $floatFieldNameAtransZ="";


global string $floatFieldNametransX="";
global string $floatFieldNametransY="";
global string $floatFieldNametransZ="";


global string $aRotatX ="0.0";
global string $aRotatY ="0.0";
global string $aRotatZ ="0.0";
global string $floatFieldNameArotatX="";
global string $floatFieldNameArotatY="";
global string $floatFieldNameArotatZ="";


global string $floatFieldNamerotatX="";
global string $floatFieldNamerotatY="";
global string $floatFieldNamerotatZ="";

global string $aScaleX ="0.0";
global string $aScaleY ="0.0";
global string $aScaleZ ="0.0";
global string $floatFieldNameAscaleX="";
global string $floatFieldNameAscaleY="";
global string $floatFieldNameAscaleZ="";

global string $floatFieldNamescaleX="";
global string $floatFieldNamescaleY="";
global string $floatFieldNamescaleZ="";
global string $fieldstat="0";

global proc string jgArrToStr (string $array[], int $index) {  
  
     // Get Index From Array  
     string $obj = $array[$index] ;  
   
     // Return  
     return $obj ;  
   
}  
  

  


global proc objectupdate() {
global string $fieldstat;
global string $aTransX;
global string $aTransY;
global string $aTransZ;
global string $floatFieldNameAtransX;
global string $floatFieldNameAtransY;
global string $floatFieldNameAtransZ;
global string $aRotatX;
global string $aRotatY;
global string $aRotatZ;
global string $floatFieldNameArotatX;
global string $floatFieldNameArotatY;
global string $floatFieldNameArotatZ;
global string $aScaleX;
global string $aScaleY;
global string $aScaleZ;
global string $floatFieldNameAscaleX;
global string $floatFieldNameAscaleY;
global string $floatFieldNameAscaleZ;

if ( size(`filterExpand -sm 12`) > 0 || size(`filterExpand -sm 9`) > 0 || size(`filterExpand -sm 10`) > 0
|| size(`filterExpand -sm 11`) > 0 ) {
$fieldstat="1";
string $selobs[]= `filterExpand -ex true -sm 12`;
string $jamin = jgArrToStr(`filterExpand -ex true -sm 12`, 0) ;  



$aTransX =`getAttr $jamin.translateX`;
$aTransY =`getAttr $jamin.translateY`;
$aTransZ =`getAttr $jamin.translateZ`;
$fatransX= (float)$aTransX;
$fatransY= (float)$aTransY;
$fatransZ= (float)$aTransZ;
$aRotatX =`getAttr $jamin.rotateX`;
$aRotatY =`getAttr $jamin.rotateY`;
$aRotatZ =`getAttr $jamin.rotateZ`;
$farotatX= (float)$aRotatX;
$farotatY= (float)$aRotatY;
$farotatZ= (float)$aRotatZ;
$aScaleX =`getAttr $jamin.scaleX`;
$aScaleY =`getAttr $jamin.scaleY`;
$aScaleZ =`getAttr $jamin.scaleZ`;
$fascaleX= (float)$aScaleX;
$fascaleY= (float)$aScaleY;
$fascaleZ= (float)$aScaleZ;
$fieldstat="1";
$ifieldstat= (int)$fieldstat;

floatField -edit -value $fatransX -enable $ifieldstat $floatFieldNameAtransX;
floatField -edit -value $fatransY -enable $ifieldstat $floatFieldNameAtransY;
floatField -edit -value $fatransZ -enable $ifieldstat $floatFieldNameAtransZ;
floatField -edit -value $farotatX -enable $ifieldstat $floatFieldNameArotatX;
floatField -edit -value $farotatY -enable $ifieldstat $floatFieldNameArotatY;
floatField -edit -value $farotatZ -enable $ifieldstat $floatFieldNameArotatZ;   
floatField -edit -value $fascaleX -enable $ifieldstat $floatFieldNameAscaleX;
floatField -edit -value $fascaleY -enable $ifieldstat $floatFieldNameAscaleY;
floatField -edit -value $fascaleZ -enable $ifieldstat $floatFieldNameAscaleZ;
}
else{
$fieldstat="0";
$ifieldstat= (int)$fieldstat;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameAtransX;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameAtransY;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameAtransZ;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameArotatX;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameArotatY;
floatField -edit -value 0.0 -enable $ifieldstat $floatFieldNameArotatZ;   
floatField -edit -value 1.0 -enable $ifieldstat $floatFieldNameAscaleX;
floatField -edit -value 1.0 -enable $ifieldstat $floatFieldNameAscaleY;
floatField -edit -value 1.0 -enable $ifieldstat $floatFieldNameAscaleZ;

}
}

global proc moveControl() {
global string $floatFieldNametransX;
global string $floatFieldNametransY;
global string $floatFieldNametransZ;

$Xvalue = `floatField -query -value $floatFieldNametransX`;
$Yvalue = `floatField -query -value $floatFieldNametransY`;
$Zvalue = `floatField -query -value $floatFieldNametransZ`;
move -r -moveXYZ $Xvalue $Yvalue $Zvalue;

objectupdate();

}


global proc AmoveControl() {
global string $floatFieldNameAtransX;
global string $floatFieldNameAtransY;
global string $floatFieldNameAtransZ;

$Xvalue = `floatField -query -value $floatFieldNameAtransX`;
$Yvalue = `floatField -query -value $floatFieldNameAtransY`;
$Zvalue = `floatField -query -value $floatFieldNameAtransZ`;
move -a -moveXYZ $Xvalue $Yvalue $Zvalue;
objectupdate();

}





global proc AmoveControlX() {
global string $floatFieldNameAtransX;

$Xvalue = `floatField -query -value $floatFieldNameAtransX`;
move -a -x $Xvalue;
objectupdate();

}

global proc moveControlX() {
global string $floatFieldNametransX;

$Xvalue = `floatField -query -value $floatFieldNametransX`;
move -r -x $Xvalue;
objectupdate();

}

global proc AmoveControlY() {
global string $floatFieldNameAtransY;

$Yvalue = `floatField -query -value $floatFieldNameAtransY`;
move -a -y $Yvalue;
objectupdate();
}
global proc moveControlY() {
global string $floatFieldNametransY;

$Yvalue = `floatField -query -value $floatFieldNametransY`;
move -r -y $Yvalue;
objectupdate();
}
global proc AmoveControlZ() {
global string $floatFieldNameAtransZ;

$Zvalue = `floatField -query -value $floatFieldNameAtransZ`;
move -a -z $Zvalue;
objectupdate();
}

global proc moveControlZ() {
global string $floatFieldNametransZ;

$Zvalue = `floatField -query -value $floatFieldNametransZ`;
move -r -z $Zvalue;
objectupdate();
}



global proc rotateControl() {
global string $floatFieldNamerotatX;
global string $floatFieldNamerotatY;
global string $floatFieldNamerotatZ;

$Xvalue = `floatField -query -value $floatFieldNamerotatX`;
$Yvalue = `floatField -query -value $floatFieldNamerotatY`;
$Zvalue = `floatField -query -value $floatFieldNamerotatZ`;
rotate -r -rotateXYZ $Xvalue $Yvalue $Zvalue;

objectupdate();


}


global proc ArotateControl() {
global string $floatFieldNameArotatX;
global string $floatFieldNameArotatY;
global string $floatFieldNameArotatZ;

$Xvalue = `floatField -query -value $floatFieldNameArotatX`;
$Yvalue = `floatField -query -value $floatFieldNameArotatY`;
$Zvalue = `floatField -query -value $floatFieldNameArotatZ`;
rotate -a -rotateXYZ $Xvalue $Yvalue $Zvalue;

objectupdate();


}



global proc rotateControlX() {

global string $floatFieldNamerotatX;

$Xvalue = `floatField -query -value $floatFieldNamerotatX`;
rotate -r -x $Xvalue;
objectupdate();

}
global proc ArotateControlX() {

global string $floatFieldNameArotatX;

$Xvalue = `floatField -query -value $floatFieldNameArotatX`;
rotate -a -x $Xvalue;
objectupdate();

}

global proc rotateControlY() {
global string $floatFieldNamerotatY;

$Yvalue = `floatField -query -value $floatFieldNamerotatY`;
rotate -r -y $Yvalue;
objectupdate();

}
global proc ArotateControlY() {
global string $floatFieldNameArotatY;

$Yvalue = `floatField -query -value $floatFieldNameArotatY`;
rotate -a -y $Yvalue;
objectupdate();

}

global proc rotateControlZ() {
global string $floatFieldNamerotatZ;

$Zvalue = `floatField -query -value $floatFieldNamerotatZ`;
rotate -r -z $Zvalue;
objectupdate();

}
global proc ArotateControlZ() {
global string $floatFieldNameArotatZ;

$Zvalue = `floatField -query -value $floatFieldNameArotatZ`;
rotate -a -z $Zvalue;
objectupdate();

}


global proc scaleControl() {
global string $floatFieldNamescaleX;
global string $floatFieldNamescaleY;
global string $floatFieldNamescaleZ;


$Xvalue = `floatField -query -value $floatFieldNamescaleX`;
$Yvalue = `floatField -query -value $floatFieldNamescaleY`;
$Zvalue = `floatField -query -value $floatFieldNamescaleZ`;
scale -r -scaleXYZ $Xvalue $Yvalue $Zvalue;
objectupdate();


}
global proc AscaleControl() {
global string $floatFieldNameAscaleX;
global string $floatFieldNameAscaleY;
global string $floatFieldNameAscaleZ;


$Xvalue = `floatField -query -value $floatFieldNameAscaleX`;
$Yvalue = `floatField -query -value $floatFieldNameAscaleY`;
$Zvalue = `floatField -query -value $floatFieldNameAscaleZ`;
scale -a -scaleXYZ $Xvalue $Yvalue $Zvalue;
objectupdate();


}

global proc scaleControlX() {
global string $floatFieldNamescaleX;
$Xvalue = `floatField -query -value $floatFieldNamescaleX`;
scale -r -x $Xvalue;
objectupdate();
}
global proc AscaleControlX() {
global string $floatFieldNameAscaleX;
$Xvalue = `floatField -query -value $floatFieldNameAscaleX`;
scale -a -x $Xvalue;
objectupdate();
}

global proc scaleControlY() {
global string $floatFieldNamescaleY;
$Yvalue = `floatField -query -value $floatFieldNamescaleY`;
scale -r -y $Yvalue;
objectupdate();
}
global proc AscaleControlY() {
global string $floatFieldNameAscaleY;
$Yvalue = `floatField -query -value $floatFieldNameAscaleY`;
scale -a -y $Yvalue;
objectupdate();
}

global proc scaleControlZ() {
global string $floatFieldNamescaleZ;
$Zvalue = `floatField -query -value $floatFieldNamescaleZ`;
scale -r -z $Zvalue;
objectupdate();
}
global proc AscaleControlZ() {
global string $floatFieldNameAscaleZ;
$Zvalue = `floatField -query -value $floatFieldNameAscaleZ`;
scale -a -z $Zvalue;
objectupdate();
}





if ( `window -exists TranfromControlWindow` ) {
deleteUI TranfromControlWindow;
}
window -restoreCommand "objectupdate();" -t "Transformation Control" TranfromControlWindow;


$fatransX= (float)$aTransX;
$fatransY= (float)$aTransY;
$fatransZ= (float)$aTransZ;


$faRotatX= (float)$aRotatX;
$faRotatY= (float)$aRotatY;
$faRotatZ= (float)$aRotatZ;

$faScaleX= (float)$aScaleX;
$faScaleY= (float)$aScaleY;
$faScaleZ= (float)$aScaleZ;



rowColumnLayout -numberOfColumns 1;
frameLayout -label "";
rowColumnLayout -numberOfColumns 2;
text -l "Object Selection";   text -l "Objects/Componants";
setParent ..;

frameLayout -label "TRANSLATE";
rowColumnLayout -numberOfColumns 4;
text -l "Absolute:World"; text -l " ";  text -l "OffSet:World"; text -l " ";
text -l "X"; $floatFieldNameAtransX= `floatField -value $fatransX -enterCommand "AmoveControlX();" `;
text -l "X"; $floatFieldNametransX =`floatField -enterCommand "moveControlX();" `;
text -l "Y"; $floatFieldNameAtransY =`floatField -value $fatransY -enterCommand "AmoveControlY();" `;  
text -l "Y"; $floatFieldNametransY =`floatField -enterCommand "moveControlY();" `;
text -l "Z"; $floatFieldNameAtransZ =`floatField -value $fatransZ -enterCommand "AmoveControlZ();" `;  
text -l "Z"; $floatFieldNametransZ =`floatField -enterCommand "moveControlZ();" `;
button -l "Abolute:Move" -command "AmoveControl();";text -l " ";
button -l "Relative:Move" -command "moveControl();";
setParent ..;

frameLayout -label "ROTATE";
rowColumnLayout -numberOfColumns 4;
text -l "Absolute:World"; text -l " ";  text -l "OffSet:World"; text -l " ";
text -l "X"; $floatFieldNameArotatX= `floatField -value $faRotatX -enterCommand "ArotateControlX();"`;  
text -l "X"; $floatFieldNamerotatX =`floatField -enterCommand "rotateControlX();" `;
text -l "Y"; $floatFieldNameArotatY =`floatField -value $faRotatY -enterCommand "ArotateControlY();"`;  
text -l "Y"; $floatFieldNamerotatY =`floatField -enterCommand "rotateControlY();"`;
text -l "Z"; $floatFieldNameArotatZ =`floatField -value $faRotatZ -enterCommand "ArotateControlZ();"`;    
text -l "Z"; $floatFieldNamerotatZ =`floatField -enterCommand "rotateControlZ();"`;
button -l "Abolute:Rotate" -command "ArotateControl();";text -l " ";
button -l "Relative:Rotate" -command "rotateControl();";
setParent ..;

frameLayout -label "SCALE";
rowColumnLayout -numberOfColumns 4;
text -l "Absolute:World"; text -l " ";  text -l "OffSet:World"; text -l " ";
text -l "X"; $floatFieldNameAscaleX = `floatField -value $faScaleX -enterCommand "AscaleControlX();"`;    
text -l "X"; $floatFieldNamescaleX =`floatField -value 1.0 -enterCommand "scaleControlX();"`;
text -l "Y"; $floatFieldNameAscaleY = `floatField -value $faScaleY -enterCommand "AscaleControlY();"`;    
text -l "Y"; $floatFieldNamescaleY =`floatField -value 1.0 -enterCommand "scaleControlY();"`;
text -l "Z"; $floatFieldNameAscaleZ = `floatField -value $faScaleZ -enterCommand "AscaleControlZ();"`;    
text -l "Z"; $floatFieldNamescaleZ =`floatField -value 1.0 -enterCommand "scaleControlZ();"`;
button -l "Abolute:Scale" -command "AscaleControl();";text -l " ";
button -l "Relative:Scale" -command "scaleControl();";
setParent ..;
button -l "Update Selection" -command "objectupdate();";

objectupdate();
showWindow TranfromControlWindow;
MAYA:
A simple Mel script to handle Absolute and Relative values in world space.
-----------------------------------------------------------------------------------------------
BUGS: The script wont run if there are more then two Objects selected, But if u want is to give relative transform to the more then one object at ones. Run the Script with out any selections or with only one selection. and then after the script runs make as many selections u want and use relative transforms. ABSOLUTE:WORLD FIELDS DON'T WORK ON MORE THE ONE OBJECT AT ONCE.
-----------------------------------------------------------------------------------------------
HOW TO USE:
On start up it will take in the selected objects(not components) transform attributes and update Absolute:World fields.
ABSOLUTE:WORLD - This is the field that controls then transform attributes of an object. This can be done in attribute editor too. but here it is provided for fast workflow in mind.
RELATIVE:WORLD - This in this field if u enter a value and process it . it will add up to the absolute value or the value present in the attribute.
BUTTONS AND EVENT HANDLERS - Press buttons on the respective areas to update all X Y Z values of that transform attribute. After u type a value press NUMPAD Enter to process that value.

-----------------------------------------------------------------------------------------------
IMPLEMENTATION:

The script can be saved as a shelf button , or can make a HOTKEY out of it. When the HOTKEY is made. the name of the HOTKEY can be used as a command.
A tutorial on how to make a shelf button for the script
[link]
--------------------------
How to Create a Hotkey

IF u want to create a Hotkey with the script
Go to Window-->Settings/Preferences-- >Hotkey Editor
When the editor opens from Categories go to "user".And press "New" button and enter as following;

Name: TransformControltool
Description: Controls the transformation
Category: User
Command: *here paste the script i have provided above*

Now press "Accept" button.
There u have created a command now now u can assign a hotkey using the field on the right "Assign New Hotkeys"
As u have created the Command now in the MEL area if u type "TransformControltool" and enter it will execute the script

Enjoy

-----------------------------------------------------------------------------------------------------
Your Free to use this script in any way, IT would be really appreciated if you would give ideas and advice on how to improve this simple script.
© 2011 - 2024 LOckaduda
Comments0
Join the community to add your comment. Already a deviant? Log In