iLegacy
04-29-2006, 09:50 PM
Hi guys,
here i will present you my basic MEL scripts. Comments & critique are very welcome!
Index (3 Scrips)
-----------------
1. rotate Objects
2. move only 2 axis
3. change culling (double sided)
4. mass uv transfer
5. vertex mode
1. rotate Objects
------------------
Explaination
-------------
The script rotates and scales selected objects by random values. Simply put the values
in the textfields and press the "ENTER"-key at your NUMLOCK block til you are satisfied!
x,y,z = the axis
r = rotate (the rotate result is a random valiu between 0 and the entered angel)
smin = min. scale value
smax = max. scale value (the scale result is a random value between smin and smax)
http://www.simont.de/downloads/robj_for_cgtalk.jpg
The Code
----------
proc rotateObj()
{
//Hole alle Werte aus den Textfeldern in die Variablen
float $objx = `textField -q -text txt_rx`;
float $objy = `textField -q -text txt_ry`;
float $objz = `textField -q -text txt_rz`;
float $obj_sxmin = `textField -q -text txt_sxmin`;
float $obj_sxmax = `textField -q -text txt_sxmax`;
float $obj_symin = `textField -q -text txt_symin`;
float $obj_symax = `textField -q -text txt_symax`;
float $obj_szmin = `textField -q -text txt_szmin`;
float $obj_szmax = `textField -q -text txt_szmax`;
//Rausfinden welche Objekte selektiert sind
string $objselected[] = `ls -sl`;
$objall = size($objselected);
$obji=0;
while ($obji < $objall)
{
//OBJEKTE ROTIEREN
if ($objx>0)
{
$objrx = rand($objx);
setAttr ($objselected[$obji]+".rotateX") $objrx;
}
if ($objy>0)
{
$objry = rand($objy);
setAttr ($objselected[$obji]+".rotateY") $objry;
}
if ($objz>0)
{
$objrz = rand($objz);
setAttr ($objselected[$obji]+".rotateZ") $objrz;
}
//OBJEKTE SKALEN
//X SCALEN
if (($obj_sxmin>0) || ($obj_sxmax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_sxmin,$obj_sxmax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleX") $scale_rand;
}
//Y SCALEN
if (($obj_symin>0) || ($obj_symax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_symin,$obj_symax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleY") $scale_rand;
}
//Z SCALEN
if (($obj_szmin>0) || ($obj_szmax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_szmin,$obj_szmax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleZ") $scale_rand;
}
$obji++;
}
}
int $checked;
string $huhu = `window -menuBar false -title "rObj" -mnb 1 -tlb 1 -resizeToFitChildren 1`;
gridLayout -numberOfColumns 4 -cellWidth 30 -cellHeight 20;
text " ";
text "r";
text "smin";
text "smax";
text "x";
string $objtext_rx = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_rx`; //rotateX
string $objtext_sxmin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_sxmin`; //scaleX MIN
string $objtext_sxmax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_sxmax`; //scaleX MAX
text "y";
string $objtext_ry = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_ry`; //rotateY
string $objtext_symin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_symin`; //scaleY MIN
string $objtext_symax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_symax`; //scaleY MAX
text -l "z";
string $objtext_rz = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_rz`; //rotateZ
string $objtext_szmin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_szmin`; //scaleZ MIN
string $objtext_szmax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_szmax`; //scaleZ MAX
window -e -w 127 -h 105 $huhu;
showWindow;
[b]2. move only 2 axis
------------------
Explaination
-------------
Locks x,y or z axis in succession of one selected object. Now objects can be
moved only along two axis.
First execute: lock x
Second execute: lock y
Third execute: lock z
Fourth execute: unlock all
It's a good way if you set a hotkey (in my case "l" for "lock").
The Code
----------
string $all[] = `ls -sl -type mesh`;
int $i,$x,$y,$z;
//get state of lock/unlock and put it to x,y or z
if (`getAttr -lock ($all[0]+".tx")` == 1) {$x=1;} else {$x=0;}
if (`getAttr -lock ($all[0]+".ty")` == 1) {$y=1;} else {$y=0;}
if (`getAttr -lock ($all[0]+".tz")` == 1) {$z=1;} else {$z=0;}
if (($x==0) && ($y==0) && ($z==0))
{
setAttr -lock true ($all[0]+".tx");
}
else
if ($x==1)
{
setAttr -lock false ($all[0]+".tx");
setAttr -lock true ($all[0]+".ty");
}
else
if ($y==1)
{
setAttr -lock false ($all[0]+".ty");
setAttr -lock true ($all[0]+".tz");
}
else
if ($z==1)
{
setAttr -lock false ($all[0]+".tz");
}
[B]3. change culling
------------------
Explaination
-------------
The scripts changes the state of "double sided" of all objects i the scene to 1 (first execution of the script) or 0 (second execution of the script). You can very fast check if the objects normals are correct.
It's a good way if you set a hotkey.
The Code
----------
string $all[] = `ls -l -type mesh`;
int $i = 0;
int $onoff = getAttr ($all[0]+".doubleSided");
if ($onoff == 0) $onoff=1; else $onoff=0;
while ($i < size($all))
{
setAttr ($all[$i]+".doubleSided") $onoff;
$i++;
}
4. mass uv transfer
------------------
Explaination
-------------
With this script you are able to transfer the uv set of the last selected to all other selected objects. Thats very usefull if you have a huge amount of equal (for example) stones or something and like to change the uv set for all of them.
Simply select all objects containing the old and last but not least the object with the new
uv set.
It's a good way if you set a hotkey.
The Code
----------
//This script will replace the uv sets of all selected objects with the uv set of the last selected object
string $list[] = `ls -sl`;
int $i = 0;
while ($i < (size($list)-1))
{
polyTransfer -vc 0 -uv 1 -v 0 -ao $list[size($list)-1] $list[$i];
$i++;
}
5. vertex mode
------------------
Explaination
-------------
When you attach this script to a hotkey, you can change the selection mode to "vertex" for the current selection. Replace "vertex" with "facet" (for face selection) or "egde" (for edge selection).
The Code
----------
string $list[] = `ls -sl`;
int $i = 0;
while ($i <= (size($list)-1))
{
print $list[$i];
doMenuComponentSelection($list[$i], "vertex");
$i++;
}
here i will present you my basic MEL scripts. Comments & critique are very welcome!
Index (3 Scrips)
-----------------
1. rotate Objects
2. move only 2 axis
3. change culling (double sided)
4. mass uv transfer
5. vertex mode
1. rotate Objects
------------------
Explaination
-------------
The script rotates and scales selected objects by random values. Simply put the values
in the textfields and press the "ENTER"-key at your NUMLOCK block til you are satisfied!
x,y,z = the axis
r = rotate (the rotate result is a random valiu between 0 and the entered angel)
smin = min. scale value
smax = max. scale value (the scale result is a random value between smin and smax)
http://www.simont.de/downloads/robj_for_cgtalk.jpg
The Code
----------
proc rotateObj()
{
//Hole alle Werte aus den Textfeldern in die Variablen
float $objx = `textField -q -text txt_rx`;
float $objy = `textField -q -text txt_ry`;
float $objz = `textField -q -text txt_rz`;
float $obj_sxmin = `textField -q -text txt_sxmin`;
float $obj_sxmax = `textField -q -text txt_sxmax`;
float $obj_symin = `textField -q -text txt_symin`;
float $obj_symax = `textField -q -text txt_symax`;
float $obj_szmin = `textField -q -text txt_szmin`;
float $obj_szmax = `textField -q -text txt_szmax`;
//Rausfinden welche Objekte selektiert sind
string $objselected[] = `ls -sl`;
$objall = size($objselected);
$obji=0;
while ($obji < $objall)
{
//OBJEKTE ROTIEREN
if ($objx>0)
{
$objrx = rand($objx);
setAttr ($objselected[$obji]+".rotateX") $objrx;
}
if ($objy>0)
{
$objry = rand($objy);
setAttr ($objselected[$obji]+".rotateY") $objry;
}
if ($objz>0)
{
$objrz = rand($objz);
setAttr ($objselected[$obji]+".rotateZ") $objrz;
}
//OBJEKTE SKALEN
//X SCALEN
if (($obj_sxmin>0) || ($obj_sxmax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_sxmin,$obj_sxmax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleX") $scale_rand;
}
//Y SCALEN
if (($obj_symin>0) || ($obj_symax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_symin,$obj_symax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleY") $scale_rand;
}
//Z SCALEN
if (($obj_szmin>0) || ($obj_szmax>0)) //nur eins der beiden muss 377ber 0 sein damit rand in kraft treten kann
{
//print("test!\n");
$scale_rand = rand($obj_szmin,$obj_szmax);
//print($scale_rand+"\n");
setAttr ($objselected[$obji]+".scaleZ") $scale_rand;
}
$obji++;
}
}
int $checked;
string $huhu = `window -menuBar false -title "rObj" -mnb 1 -tlb 1 -resizeToFitChildren 1`;
gridLayout -numberOfColumns 4 -cellWidth 30 -cellHeight 20;
text " ";
text "r";
text "smin";
text "smax";
text "x";
string $objtext_rx = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_rx`; //rotateX
string $objtext_sxmin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_sxmin`; //scaleX MIN
string $objtext_sxmax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_sxmax`; //scaleX MAX
text "y";
string $objtext_ry = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_ry`; //rotateY
string $objtext_symin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_symin`; //scaleY MIN
string $objtext_symax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_symax`; //scaleY MAX
text -l "z";
string $objtext_rz = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_rz`; //rotateZ
string $objtext_szmin = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_szmin`; //scaleZ MIN
string $objtext_szmax = `textField -text "0" -width 30 -enterCommand "rotateObj" txt_szmax`; //scaleZ MAX
window -e -w 127 -h 105 $huhu;
showWindow;
[b]2. move only 2 axis
------------------
Explaination
-------------
Locks x,y or z axis in succession of one selected object. Now objects can be
moved only along two axis.
First execute: lock x
Second execute: lock y
Third execute: lock z
Fourth execute: unlock all
It's a good way if you set a hotkey (in my case "l" for "lock").
The Code
----------
string $all[] = `ls -sl -type mesh`;
int $i,$x,$y,$z;
//get state of lock/unlock and put it to x,y or z
if (`getAttr -lock ($all[0]+".tx")` == 1) {$x=1;} else {$x=0;}
if (`getAttr -lock ($all[0]+".ty")` == 1) {$y=1;} else {$y=0;}
if (`getAttr -lock ($all[0]+".tz")` == 1) {$z=1;} else {$z=0;}
if (($x==0) && ($y==0) && ($z==0))
{
setAttr -lock true ($all[0]+".tx");
}
else
if ($x==1)
{
setAttr -lock false ($all[0]+".tx");
setAttr -lock true ($all[0]+".ty");
}
else
if ($y==1)
{
setAttr -lock false ($all[0]+".ty");
setAttr -lock true ($all[0]+".tz");
}
else
if ($z==1)
{
setAttr -lock false ($all[0]+".tz");
}
[B]3. change culling
------------------
Explaination
-------------
The scripts changes the state of "double sided" of all objects i the scene to 1 (first execution of the script) or 0 (second execution of the script). You can very fast check if the objects normals are correct.
It's a good way if you set a hotkey.
The Code
----------
string $all[] = `ls -l -type mesh`;
int $i = 0;
int $onoff = getAttr ($all[0]+".doubleSided");
if ($onoff == 0) $onoff=1; else $onoff=0;
while ($i < size($all))
{
setAttr ($all[$i]+".doubleSided") $onoff;
$i++;
}
4. mass uv transfer
------------------
Explaination
-------------
With this script you are able to transfer the uv set of the last selected to all other selected objects. Thats very usefull if you have a huge amount of equal (for example) stones or something and like to change the uv set for all of them.
Simply select all objects containing the old and last but not least the object with the new
uv set.
It's a good way if you set a hotkey.
The Code
----------
//This script will replace the uv sets of all selected objects with the uv set of the last selected object
string $list[] = `ls -sl`;
int $i = 0;
while ($i < (size($list)-1))
{
polyTransfer -vc 0 -uv 1 -v 0 -ao $list[size($list)-1] $list[$i];
$i++;
}
5. vertex mode
------------------
Explaination
-------------
When you attach this script to a hotkey, you can change the selection mode to "vertex" for the current selection. Replace "vertex" with "facet" (for face selection) or "egde" (for edge selection).
The Code
----------
string $list[] = `ls -sl`;
int $i = 0;
while ($i <= (size($list)-1))
{
print $list[$i];
doMenuComponentSelection($list[$i], "vertex");
$i++;
}
