PDA

View Full Version : Let me know what you think of my first script :)


Freshfromthegrave
02-14-2011, 09:03 AM
Hey guys so i finished my first proper script a while back and thought i'd finally post it up here to see what people thought of it :) it's a randomizer, takes all your objects and randomizes translate, rotate and/or scale on the axis of your choosing between limits of your choosing. i'm still very new to scripting and i have no doubt there's a better way of doing this :P this way of doing it seems kinda slow but it works and it serves it's purpose :) there was a problem with window sizing but you can just resize it and it keeps it's sizing whenever you run it. let me know what you think!

//------------------------------------------------------------------------------//
// Script: SMO_RandomizeXForm.mel
//
// Version: 1.0
//
// Author: Steven Olver
// stevenolver@gmail.com
//
// Date: 8th February 2011
//
// Description: Randomizes translate, rotate and scale transforms
// randomly between editable minimum and maximum values.
// Also capable of switching between absolute and
// relative transforms.
//
// Usage: Run script from script editor or shelf. Select objects
// and tick checkboxes for transforms you wish to apply to.
// Input min and max values for the transforms and select
// absolute or relative, then press ok. The window will
// retain so you can edit values or hit ok again to
// randomize selected transforms again.
//
// (C) Copyright Steven Olver 2011
//
//------------------------------------------------------------------------------//




//Delete and define window
if ( `window -exists SMO_RandomizeXFormWindow` )
{
deleteUI SMO_RandomizeXFormWindow;
}
window -t "SMO_RandomizeXForm" -rtf true SMO_RandomizeXFormWindow;

//Define layout elements
formLayout -numberOfDivisions 425 SMO_RandomizeXForm_Form;

text -l "X Axis" XAxis;
text -l "Min" XMin;
text -l "Max" XMax;

text -l "Y Axis" YAxis;
text -l "Min" YMin;
text -l "Max" YMax;

text -l "Z Axis" ZAxis;
text -l "Min" ZMin;
text -l "Max" ZMax;

text "Translate";

floatField -w 50 TranslateXMin;
floatField -w 50 TranslateXMax;
checkBox -l "" TranslateXCheckBox;

floatField -w 50 TranslateYMin;
floatField -w 50 TranslateYMax;
checkBox -l "" TranslateYCheckBox;

floatField -w 50 TranslateZMin;
floatField -w 50 TranslateZMax;
checkBox -l "" TranslateZCheckBox;


text "Rotate";

floatField -w 50 RotateXMin;
floatField -w 50 RotateXMax;
checkBox -l "" RotateXCheckBox;

floatField -w 50 RotateYMin;
floatField -w 50 RotateYMax;
checkBox -l "" RotateYCheckBox;

floatField -w 50 RotateZMin;
floatField -w 50 RotateZMax;
checkBox -l "" RotateZCheckBox;


text "Scale";

floatField -w 50 ScaleXMin;
floatField -w 50 ScaleXMax;
checkBox -l "" ScaleXCheckBox;

floatField -w 50 ScaleYMin;
floatField -w 50 ScaleYMax;
checkBox -l "" ScaleYCheckBox;

floatField -w 50 ScaleZMin;
floatField -w 50 ScaleZMax;
checkBox -l "" ScaleZCheckBox;



radioCollection;
radioButton -sl "Absolute";
radioButton "Relative";

button -label "OK" -command "executeSMO_RandomizeXForm" OKButton;

//Defining element positions
formLayout -edit


//Text
-af XAxis "top" 10
-af XAxis "left" 135

-af XMin "top" 25
-af XMin "left" 112

-af XMax "top" 25
-af XMax "left" 170


-af YAxis "top" 10
-af YAxis "left" 285

-af YMin "top" 25
-af YMin "left" 262

-af YMax "top" 25
-af YMax "left" 320


-af ZAxis "top" 10
-af ZAxis "left" 435

-af ZMin "top" 25
-af ZMin "left" 412

-af ZMax "top" 25
-af ZMax "left" 470


//Translate Controls
-af Translate "top" 43
-af Translate "left" 10

-af TranslateXMin "top" 40
-af TranslateXMin "left" 95

-af TranslateXMax "top" 40
-af TranslateXMax "left" 155

-af TranslateXCheckBox "top" 44
-af TranslateXCheckBox "left" 75


-af TranslateYMin "top" 40
-af TranslateYMin "left" 245

-af TranslateYMax "top" 40
-af TranslateYMax "left" 305

-af TranslateYCheckBox "top" 44
-af TranslateYCheckBox "left" 225


-af TranslateZMin "top" 40
-af TranslateZMin "left" 395

-af TranslateZMax "top" 40
-af TranslateZMax "left" 455

-af TranslateZCheckBox "top" 44
-af TranslateZCheckBox "left" 375


//Rotate Controls
-af Rotate "top" 63
-af Rotate "left" 10

-af RotateXMin "top" 60
-af RotateXMin "left" 95

-af RotateXMax "top" 60
-af RotateXMax "left" 155

-af RotateXCheckBox "top" 64
-af RotateXCheckBox "left" 75


-af RotateYMin "top" 60
-af RotateYMin "left" 245

-af RotateYMax "top" 60
-af RotateYMax "left" 305

-af RotateYCheckBox "top" 64
-af RotateYCheckBox "left" 225


-af RotateZMin "top" 60
-af RotateZMin "left" 395

-af RotateZMax "top" 60
-af RotateZMax "left" 455

-af RotateZCheckBox "top" 64
-af RotateZCheckBox "left" 375


//Scale Controls
-af Scale "top" 83
-af Scale "left" 10

-af ScaleXMin "top" 80
-af ScaleXMin "left" 95

-af ScaleXMax "top" 80
-af ScaleXMax "left" 155

-af ScaleXCheckBox "top" 84
-af ScaleXCheckBox "left" 75


-af ScaleYMin "top" 80
-af ScaleYMin "left" 245

-af ScaleYMax "top" 80
-af ScaleYMax "left" 305

-af ScaleYCheckBox "top" 84
-af ScaleYCheckBox "left" 225


-af ScaleZMin "top" 80
-af ScaleZMin "left" 395

-af ScaleZMax "top" 80
-af ScaleZMax "left" 455

-af ScaleZCheckBox "top" 84
-af ScaleZCheckBox "left" 375


//Radio and Buttons
-af Absolute "top" 105
-af Absolute "left" 75

-af Relative "top" 120
-af Relative "left" 75


-af OKButton "top" 145
-af OKButton "left" 75

SMO_RandomizeXForm_Form;

showWindow SMO_RandomizeXFormWindow;



// Proc executed when OK button is pressed
proc executeSMO_RandomizeXForm()
{

//Main loop run though for each object within selection

string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//Checkbox queries

int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;

int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;





//Main transform execution loops. Switch/case is used to determine
//absolute or relative. If else loop used to query the checkbox
//variables and do the transform if yes, do nothing if no.





//TranslateXExecute

switch($RadioButtonAbsolute)
{
case true:
if ($TranslateXCheckboxOnOff == 1)
{
float $InputTransXMin = `floatField -q -v TranslateXMin`;
float $InputTransXMax = `floatField -q -v TranslateXMax`;

float $InputTransYMin = `getAttr ($objects+".translateY")`;
float $InputTransYMax = `getAttr ($objects+".translateY")`;

float $InputTransZMin = `getAttr ($objects+".translateZ")`;
float $InputTransZMax = `getAttr ($objects+".translateZ")`;

float $TransXRandom = rand ($InputTransXMin,$InputTransXMax);
float $TransYRandom = rand ($InputTransYMin,$InputTransYMax);
float $TransZRandom = rand ($InputTransZMin,$InputTransZMax);
xform -a -t $TransXRandom $TransYRandom $TransZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($TranslateXCheckboxOnOff == 1)
{
float $InputTransXMin = `floatField -q -v TranslateXMin`;
float $InputTransXMax = `floatField -q -v TranslateXMax`;

float $TransXRandom = rand ($InputTransXMin,$InputTransXMax);
xform -r -t $TransXRandom 0 0 $objects;
}
else
{
//nothing
}
break;
}





//TranslateYExecute

switch($RadioButtonAbsolute)
{
case true:
if ($TranslateYCheckboxOnOff == 1)
{
float $InputTransXMin = `getAttr ($objects+".translateX")`;
float $InputTransXMax = `getAttr ($objects+".translateX")`;

float $InputTransYMin = `floatField -q -v TranslateYMin`;
float $InputTransYMax = `floatField -q -v TranslateYMax`;

float $InputTransZMin = `getAttr ($objects+".translateZ")`;
float $InputTransZMax = `getAttr ($objects+".translateZ")`;

float $TransXRandom = rand ($InputTransXMin,$InputTransXMax);
float $TransYRandom = rand ($InputTransYMin,$InputTransYMax);
float $TransZRandom = rand ($InputTransZMin,$InputTransZMax);
xform -a -t $TransXRandom $TransYRandom $TransZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($TranslateYCheckboxOnOff == 1)
{
float $InputTransYMin = `floatField -q -v TranslateYMin`;
float $InputTransYMax = `floatField -q -v TranslateYMax`;

float $TransYRandom = rand ($InputTransYMin,$InputTransYMax);
xform -r -t 0 $TransYRandom 0 $objects;
}
else
{
//nothing
}
break;
}





//TranslateZExecute

switch($RadioButtonAbsolute)
{
case true:
if ($TranslateZCheckboxOnOff == 1)
{
float $InputTransXMin = `getAttr ($objects+".translateX")`;
float $InputTransXMax = `getAttr ($objects+".translateX")`;

float $InputTransYMin = `getAttr ($objects+".translateY")`;
float $InputTransYMax = `getAttr ($objects+".translateY")`;

float $InputTransZMin = `floatField -q -v TranslateZMin`;
float $InputTransZMax = `floatField -q -v TranslateZMax`;

float $TransXRandom = rand ($InputTransXMin,$InputTransXMax);
float $TransYRandom = rand ($InputTransYMin,$InputTransYMax);
float $TransZRandom = rand ($InputTransZMin,$InputTransZMax);
xform -a -t $TransXRandom $TransYRandom $TransZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($TranslateZCheckboxOnOff == 1)
{
float $InputTransZMin = `floatField -q -v TranslateZMin`;
float $InputTransZMax = `floatField -q -v TranslateZMax`;

float $TransZRandom = rand ($InputTransZMin,$InputTransZMax);
xform -r -t 0 0 $TransZRandom $objects;
}
else
{
//nothing
}
break;
}





//RotateXExecute

switch($RadioButtonAbsolute)
{
case true:
if ($RotateXCheckboxOnOff == 1)
{
float $InputRotateXMin = `floatField -q -v RotateXMin`;
float $InputRotateXMax = `floatField -q -v RotateXMax`;

float $InputRotateYMin = `getAttr ($objects+".rotateY")`;
float $InputRotateYMax = `getAttr ($objects+".rotateY")`;

float $InputRotateZMin = `getAttr ($objects+".rotateZ")`;
float $InputRotateZMax = `getAttr ($objects+".rotateZ")`;

float $RotateXRandom = rand ($InputRotateXMin,$InputRotateXMax);
float $RotateYRandom = rand ($InputRotateYMin,$InputRotateYMax);
float $RotateZRandom = rand ($InputRotateZMin,$InputRotateZMax);
xform -a -ro $RotateXRandom $RotateYRandom $RotateZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($RotateXCheckboxOnOff == 1)
{
float $InputRotateXMin = `floatField -q -v RotateXMin`;
float $InputRotateXMax = `floatField -q -v RotateXMax`;

float $RotateXRandom = rand ($InputRotateXMin,$InputRotateXMax);
xform -r -ro $RotateXRandom 0 0 $objects;
}
break;
}





//RotateYExecute

switch($RadioButtonAbsolute)
{
case true:
if ($RotateYCheckboxOnOff == 1)
{
float $InputRotateXMin = `getAttr ($objects+".rotateX")`;
float $InputRotateXMax = `getAttr ($objects+".rotateX")`;

float $InputRotateYMin = `floatField -q -v RotateYMin`;
float $InputRotateYMax = `floatField -q -v RotateYMax`;

float $InputRotateZMin = `getAttr ($objects+".rotateZ")`;
float $InputRotateZMax = `getAttr ($objects+".rotateZ")`;

float $RotateXRandom = rand ($InputRotateXMin,$InputRotateXMax);
float $RotateYRandom = rand ($InputRotateYMin,$InputRotateYMax);
float $RotateZRandom = rand ($InputRotateZMin,$InputRotateZMax);
xform -a -ro $RotateXRandom $RotateYRandom $RotateZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($RotateYCheckboxOnOff == 1)
{

float $InputRotateYMin = `floatField -q -v RotateYMin`;
float $InputRotateYMax = `floatField -q -v RotateYMax`;

float $RotateYRandom = rand ($InputRotateYMin,$InputRotateYMax);
xform -r -ro 0 $RotateYRandom 0 $objects;
}
else
{
//nothing
}
break;
}





//RotateZExecute

switch($RadioButtonAbsolute)
{
case true:
if ($RotateZCheckboxOnOff == 1)
{
float $InputRotateXMin = `getAttr ($objects+".rotateX")`;
float $InputRotateXMax = `getAttr ($objects+".rotateX")`;

float $InputRotateYMin = `getAttr ($objects+".rotateY")`;
float $InputRotateYMax = `getAttr ($objects+".rotateY")`;

float $InputRotateZMin = `floatField -q -v RotateZMin`;
float $InputRotateZMax = `floatField -q -v RotateZMax`;

float $RotateXRandom = rand ($InputRotateXMin,$InputRotateXMax);
float $RotateYRandom = rand ($InputRotateYMin,$InputRotateYMax);
float $RotateZRandom = rand ($InputRotateZMin,$InputRotateZMax);
xform -a -ro $RotateXRandom $RotateYRandom $RotateZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($RotateZCheckboxOnOff == 1)
{

float $InputRotateZMin = `floatField -q -v RotateZMin`;
float $InputRotateZMax = `floatField -q -v RotateZMax`;

float $RotateZRandom = rand ($InputRotateZMin,$InputRotateZMax);
xform -r -ro 0 0 $RotateZRandom $objects;
}
else
{
//nothing
}
break;
}




//ScaleXExecute

switch($RadioButtonAbsolute)
{
case true:
if ($ScaleXCheckboxOnOff == 1)
{
float $InputScaleXMin = `floatField -q -v ScaleXMin`;
float $InputScaleXMax = `floatField -q -v ScaleXMax`;

float $InputScaleYMin = `getAttr ($objects+".scaleY")`;
float $InputScaleYMax = `getAttr ($objects+".scaleY")`;

float $InputScaleZMin = `getAttr ($objects+".scaleZ")`;
float $InputScaleZMax = `getAttr ($objects+".scaleZ")`;

float $ScaleXRandom = rand ($InputScaleXMin,$InputScaleXMax);
float $ScaleYRandom = rand ($InputScaleYMin,$InputScaleYMax);
float $ScaleZRandom = rand ($InputScaleZMin,$InputScaleZMax);
xform -a -s $ScaleXRandom $ScaleYRandom $ScaleZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($ScaleXCheckboxOnOff == 1)
{
float $InputScaleXMin = `floatField -q -v ScaleXMin`;
float $InputScaleXMax = `floatField -q -v ScaleXMax`;

float $ScaleXRandom = rand ($InputScaleXMin,$InputScaleXMax);
xform -r -s $ScaleXRandom 1 1 $objects;
}
else
{
//nothing
}
break;
}





//ScaleYExecute

switch($RadioButtonAbsolute)
{
case true:
if ($ScaleYCheckboxOnOff == 1)
{
float $InputScaleXMin = `getAttr ($objects+".scaleX")`;
float $InputScaleXMax = `getAttr ($objects+".scaleX")`;

float $InputScaleYMin = `floatField -q -v ScaleYMin`;
float $InputScaleYMax = `floatField -q -v ScaleYMax`;

float $InputScaleZMin = `getAttr ($objects+".scaleZ")`;
float $InputScaleZMax = `getAttr ($objects+".scaleZ")`;

float $ScaleXRandom = rand ($InputScaleXMin,$InputScaleXMax);
float $ScaleYRandom = rand ($InputScaleYMin,$InputScaleYMax);
float $ScaleZRandom = rand ($InputScaleZMin,$InputScaleZMax);
xform -a -s $ScaleXRandom $ScaleYRandom $ScaleZRandom $objects;
}
else
{
//nothing
}
break;
case false:
if ($ScaleYCheckboxOnOff == 1)
{
float $InputScaleYMin = `floatField -q -v ScaleYMin`;
float $InputScaleYMax = `floatField -q -v ScaleYMax`;

float $ScaleYRandom = rand ($InputScaleYMin,$InputScaleYMax);
xform -r -s 1 $ScaleYRandom 1 $objects;
}
else
{
//nothing
}
break;
}





//ScaleZExecute

switch($RadioButtonAbsolute)
{
case true:
if ($ScaleZCheckboxOnOff == 1)
{
float $InputScaleXMin = `getAttr ($objects+".scaleX")`;
float $InputScaleXMax = `getAttr ($objects+".scaleX")`;

float $InputScaleYMin = `getAttr ($objects+".scaleY")`;
float $InputScaleYMax = `getAttr ($objects+".scaleY")`;

float $InputScaleZMin = `floatField -q -v ScaleZMin`;
float $InputScaleZMax = `floatField -q -v ScaleZMax`;

float $ScaleXRandom = rand ($InputScaleXMin,$InputScaleXMax);
float $ScaleYRandom = rand ($InputScaleYMin,$InputScaleYMax);
float $ScaleZRandom = rand ($InputScaleZMin,$InputScaleZMax);
xform -a -s $ScaleXRandom $ScaleYRandom $ScaleZRandom $objects;
}
else
{
//nothing
}
case false:
if ($ScaleZCheckboxOnOff == 1)
{
float $InputScaleZMin = `floatField -q -v ScaleZMin`;
float $InputScaleZMax = `floatField -q -v ScaleZMax`;

float $ScaleZRandom = rand ($InputScaleZMin,$InputScaleZMax);
xform -r -s 1 1 $ScaleZRandom $objects;
}
else
{
//nothing
}
break;
}


}


}

//End

uiron
02-14-2011, 03:27 PM
what i didn't like was:

too much copy paste;
for that much code, only one procedure;
it's written in MEL.

goleafsgo
02-15-2011, 03:20 AM
A few things:

I'm guessing that you worked on this in the script editor mostly? What you should do is put all this in a mel file, then make a global proc that has the same name as your script and put your UI code in that proc. And your "execute" proc should be global as well.

e.g. Dump all this in a file named MyRandomizer.mel, move all your UI code at the top into a "global proc MyRandomizer" and make your execute proc global too.

Then from your shelf button or wherever you can just call "MyRandomizer".


In terms of the actual code....

Making one formLayout and then hardcoding all the positions is a typical thing for someone to try when they are first starting out, but it can be a bit of a nightmare to maintain. Instead of using "attachForm" everywhere you should try "attachControl" in a lot of the places. That lets you place a UI control relative to another one. So instead of saying one control is 20 units away from the forms edges...then the next control is 35 units away...then the next one is 55 units away... you can say that the next control should be a certain number of units away from the control beside it.

And instead of every control being a separate thing to be attached in the formLayout you can add parts of the UI into other layouts, e.g. maybe everything for Translate is in one rowLayout, then everything for Rotate and Scale are in their own rowLayouts, and then you just add in those rowLayouts to the formLayout. Does that make sense?

For your execute function, anything that isn't changing in your for loop should be obtained before you start the loop. So all that querying of checkBoxes that you have running for each object could probably be done once before the loop starts I think? Right now if you have 100 objects then you're asking those checkBox's 100 times if they are on or not.

Those chunks of code at the bottom could probably be shortened quite a bit. Right now you query the floatField and do two getAttr's for X, Y and Z separately. You could probably change your logic so that you either query the floatField or do a getAttr for each of them and then just have to do one xform call. Does that make sense?

Freshfromthegrave
02-15-2011, 09:56 AM
hey Tim thanks for the input :) i actually do have it in a mel file i just didn't think to try and upload that to the forums xD what is the advantage to using global procs over local ones? my understanding was that if you could get by with local then you should use that?

i found making the interface like that to be time consuming but actually quite easy to control, but i'll definitely try the other options too. i didn't realise you could use more than one layout in a window o.O

that was a total facepalm on my part for putting the checkbox queries in the loop xD thanks for pointing that out, it seems to be a bit faster now too.

would you be able to explain your last paragraph though? i don't quite understand =\

thanks for you time Tim i appreciate it :) :beer:

NaughtyNathan
02-15-2011, 10:35 AM
Steven, a proc that is declared "local" to the world scope is global. It's only local when it's inside a MEL script file. Also, UI controls cannot refer directly to local procs, only to globals.

you really do need to proceduralise your code a lot more, if ever you find yourself copy/pasting the same lines of code more than once in a script (even with a slight variance in their parameters) you need to consider making it a separate proc (local! ;) ).

:nathaN

Freshfromthegrave
02-15-2011, 10:43 AM
thanks Nathan, insightful as always ^^ i actually wanted to use more procs (in fact one for each of those copy pasted bits) but i was unsure as to how =\ it's something i should probably experiment with/research more :)

goleafsgo
02-15-2011, 01:30 PM
would you be able to explain your last paragraph though? i don't quite understand =\


I didn't actually run this, so it might have typo's, but this is the kind of thing I was talking about:


// Get the current value of translate x/y/z all at once...
float $trans[] = `getAttr ($objects+".translate")`;

// Then update any of the 3 values if the check box was on.
// The min/max values here are another one that could probably be
// queried before starting the loop.
if ($TranslateXCheckboxOnOff == 1)
{
$trans[0] = rand ($InputTransXMin,$InputTransXMax);
}
if ($TranslateYCheckboxOnOff == 1)
{
$trans[1] = rand ($InputTransYMin,$InputTransYMax);
}
if ($TranslateZCheckboxOnOff == 1)
{
$trans[2] = rand ($InputTransZMin,$InputTransZMax);
}

// Now set all the values at the same time. Some of these values
// might just be the current values...some the random values.
xform -a -t $trans[0] $trans[1] $trans[2] $objects;


So this chunk of code should replace 3 of yours where you did translateX, translateY and translateZ separately. And if you really wanted to, you could make another (local) proc that takes in a string for the attribute you are setting and you could make that one proc set translate, rotate and scale.

Freshfromthegrave
02-15-2011, 02:36 PM
oh that's pretty clever dude :D (well to me lol) thanks for that i'm gonna try that out sometime and see if i can optimize it more :) still confused as to how to implement more procs though =\ is there a way to have the different checkboxes somehow point to different procs?

this is probably something super simple that i'm missing xD

Freshfromthegrave
02-15-2011, 03:06 PM
can you just use a simple if loop saying if the checkbox is ticked go to that proc? actually it probably is just that xD

Freshfromthegrave
02-16-2011, 01:54 PM
right, how do you guys like this version then? :D ok i can't attach a .mel file on the forums...

//------------------------------------------------------------------------------//
// Script: SMO_RandomizeXForm.mel
//
// Version: 1.0
//
// Author: Steven Olver
// stevenolver@gmail.com
//
// Date: 16th February 2011
//
// Description: Randomizes translate, rotate and scale transforms
// randomly between editable minimum and maximum values.
// Also capable of switching between absolute and
// relative transforms.
//
// Usage: Run script from script editor or shelf. Select objects
// and tick checkboxes for transforms you wish to apply to.
// Input min and max values for the transforms and select
// absolute or relative, then press ok. The window will
// retain so you can edit values or hit ok again to
// randomize selected transforms again.
//
// (C) Copyright Steven Olver 2011
//
//------------------------------------------------------------------------------//



global proc SMO_RandomizeXForm()
{
//Delete and define window
if ( `window -exists SMO_RandomizeXFormWindow` )
{
deleteUI SMO_RandomizeXFormWindow;
}
window -t "SMO_RandomizeXForm" -rtf true SMO_RandomizeXFormWindow;

//Define layout elements
formLayout -numberOfDivisions 425 SMO_RandomizeXForm_Form;

text -l "X Axis" XAxis;
text -l "Min" XMin;
text -l "Max" XMax;

text -l "Y Axis" YAxis;
text -l "Min" YMin;
text -l "Max" YMax;

text -l "Z Axis" ZAxis;
text -l "Min" ZMin;
text -l "Max" ZMax;

text "Translate";

floatField -w 50 TranslateXMin;
floatField -w 50 TranslateXMax;
checkBox -l "" TranslateXCheckBox;

floatField -w 50 TranslateYMin;
floatField -w 50 TranslateYMax;
checkBox -l "" TranslateYCheckBox;

floatField -w 50 TranslateZMin;
floatField -w 50 TranslateZMax;
checkBox -l "" TranslateZCheckBox;


text "Rotate";

floatField -w 50 RotateXMin;
floatField -w 50 RotateXMax;
checkBox -l "" RotateXCheckBox;

floatField -w 50 RotateYMin;
floatField -w 50 RotateYMax;
checkBox -l "" RotateYCheckBox;

floatField -w 50 RotateZMin;
floatField -w 50 RotateZMax;
checkBox -l "" RotateZCheckBox;


text "Scale";

floatField -w 50 ScaleXMin;
floatField -w 50 ScaleXMax;
checkBox -l "" ScaleXCheckBox;

floatField -w 50 ScaleYMin;
floatField -w 50 ScaleYMax;
checkBox -l "" ScaleYCheckBox;

floatField -w 50 ScaleZMin;
floatField -w 50 ScaleZMax;
checkBox -l "" ScaleZCheckBox;



radioCollection;
radioButton -sl "Absolute";
radioButton "Relative";

button -label "OK" -command "executeSMO_RandomizeXForm" OKButton;

//Defining element positions
formLayout -edit


//Text
-af XAxis "top" 10
-af XAxis "left" 135

-af XMin "top" 25
-af XMin "left" 112

-af XMax "top" 25
-af XMax "left" 170


-af YAxis "top" 10
-af YAxis "left" 285

-af YMin "top" 25
-af YMin "left" 262

-af YMax "top" 25
-af YMax "left" 320


-af ZAxis "top" 10
-af ZAxis "left" 435

-af ZMin "top" 25
-af ZMin "left" 412

-af ZMax "top" 25
-af ZMax "left" 470


//Translate Controls
-af Translate "top" 43
-af Translate "left" 10

-af TranslateXMin "top" 40
-af TranslateXMin "left" 95

-af TranslateXMax "top" 40
-af TranslateXMax "left" 155

-af TranslateXCheckBox "top" 44
-af TranslateXCheckBox "left" 75


-af TranslateYMin "top" 40
-af TranslateYMin "left" 245

-af TranslateYMax "top" 40
-af TranslateYMax "left" 305

-af TranslateYCheckBox "top" 44
-af TranslateYCheckBox "left" 225


-af TranslateZMin "top" 40
-af TranslateZMin "left" 395

-af TranslateZMax "top" 40
-af TranslateZMax "left" 455

-af TranslateZCheckBox "top" 44
-af TranslateZCheckBox "left" 375


//Rotate Controls
-af Rotate "top" 63
-af Rotate "left" 10

-af RotateXMin "top" 60
-af RotateXMin "left" 95

-af RotateXMax "top" 60
-af RotateXMax "left" 155

-af RotateXCheckBox "top" 64
-af RotateXCheckBox "left" 75


-af RotateYMin "top" 60
-af RotateYMin "left" 245

-af RotateYMax "top" 60
-af RotateYMax "left" 305

-af RotateYCheckBox "top" 64
-af RotateYCheckBox "left" 225


-af RotateZMin "top" 60
-af RotateZMin "left" 395

-af RotateZMax "top" 60
-af RotateZMax "left" 455

-af RotateZCheckBox "top" 64
-af RotateZCheckBox "left" 375


//Scale Controls
-af Scale "top" 83
-af Scale "left" 10

-af ScaleXMin "top" 80
-af ScaleXMin "left" 95

-af ScaleXMax "top" 80
-af ScaleXMax "left" 155

-af ScaleXCheckBox "top" 84
-af ScaleXCheckBox "left" 75


-af ScaleYMin "top" 80
-af ScaleYMin "left" 245

-af ScaleYMax "top" 80
-af ScaleYMax "left" 305

-af ScaleYCheckBox "top" 84
-af ScaleYCheckBox "left" 225


-af ScaleZMin "top" 80
-af ScaleZMin "left" 395

-af ScaleZMax "top" 80
-af ScaleZMax "left" 455

-af ScaleZCheckBox "top" 84
-af ScaleZCheckBox "left" 375


//Radio and Buttons
-af Absolute "top" 105
-af Absolute "left" 75

-af Relative "top" 120
-af Relative "left" 75


-af OKButton "top" 145
-af OKButton "left" 75

SMO_RandomizeXForm_Form;

showWindow SMO_RandomizeXFormWindow;
}





// Proc executed when OK button is pressed
proc executeSMO_RandomizeXForm()
{


//Checkbox queries
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;


//Loops to redirect to procs if checkboxes are ticked

//TranslateProcs
if ($TranslateXCheckboxOnOff == 1)
{
TranslateProc;
}
if ($TranslateYCheckboxOnOff == 1)
{
TranslateProc;
}
if ($TranslateZCheckboxOnOff == 1)
{
TranslateProc;
}


//RotateProcs
if ($RotateXCheckboxOnOff == 1)
{
RotateProc;
}
if ($RotateYCheckboxOnOff == 1)
{
RotateProc;
}
if ($RotateZCheckboxOnOff == 1)
{
RotateProc;
}


//ScaleProcs
if ($ScaleXCheckboxOnOff == 1)
{
ScaleProc;
}
if ($ScaleYCheckboxOnOff == 1)
{
ScaleProc;
}
if ($ScaleZCheckboxOnOff == 1)
{
ScaleProc;
}


}





//Main transform execution procs and loops. Switch/case is used to determine
//absolute or relative. If else loop used to query the checkbox
//variables and do the transform if yes, do nothing if no.

//Translate Execute
proc TranslateProc()
{


//Checkbox Queries again
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

//floatFieldQueries
float $InputTransXMin = `floatField -q -v TranslateXMin`;
float $InputTransXMax = `floatField -q -v TranslateXMax`;

float $InputTransYMin = `floatField -q -v TranslateYMin`;
float $InputTransYMax = `floatField -q -v TranslateYMax`;

float $InputTransZMin = `floatField -q -v TranslateZMin`;
float $InputTransZMax = `floatField -q -v TranslateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Translate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $TranslateRandom[] = `getAttr ($objects+".translate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
xform -a -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
case false:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
else
{
$TranslateRandom[0] = 0;
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
else
{
$TranslateRandom[1] = 0;
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
else
{
$TranslateRandom[2] = 0;
}
xform -r -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
}

}

}





//Rotate Execute
proc RotateProc()
{


//Checkbox Queries again
int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

//floatFieldQueries
float $InputRotateXMin = `floatField -q -v RotateXMin`;
float $InputRotateXMax = `floatField -q -v RotateXMax`;
float $InputRotateYMin = `floatField -q -v RotateYMin`;
float $InputRotateYMax = `floatField -q -v RotateYMax`;
float $InputRotateZMin = `floatField -q -v RotateZMin`;
float $InputRotateZMax = `floatField -q -v RotateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Rotate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $RotateRandom[] = `getAttr ($objects+".rotate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
xform -a -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
case false:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
else
{
$RotateRandom[0] = 0;
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
else
{
$RotateRandom[1] = 0;
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
else
{
$RotateRandom[2] = 0;
}
xform -r -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
}

}

}





//ScaleExecute
proc ScaleProc()
{


//Checkbox Queries again
int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;

//floatFieldQueries
float $InputScaleXMin = `floatField -q -v ScaleXMin`;
float $InputScaleXMax = `floatField -q -v ScaleXMax`;
float $InputScaleYMin = `floatField -q -v ScaleYMin`;
float $InputScaleYMax = `floatField -q -v ScaleYMax`;
float $InputScaleZMin = `floatField -q -v ScaleZMin`;
float $InputScaleZMax = `floatField -q -v ScaleZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Scale Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $ScaleRandom[] = `getAttr ($objects+".scale")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
xform -a -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
case false:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
else
{
$ScaleRandom[0] = 1;
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
else
{
$ScaleRandom[1] = 1;
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
else
{
$ScaleRandom[2] = 1;
}
xform -r -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
}

}

}
//End

should i be making all those procs global? or is it fine as is? also does anybody know of any tutorials or advice on formatting cos i think my formatting sucks xD

edit: thinking about it is there a better way to do those loops that redirect to the procs? i have a feeling it's doing it three times if you select three translate checkboxes etc...

is there a way to make a conditional that goes: if any of these are true then go to that proc?

Freshfromthegrave
02-17-2011, 08:13 AM
k sorted it :) seems a lot faster now too :D

//------------------------------------------------------------------------------//
// Script: SMO_RandomizeXForm.mel
//
// Version: 1.0
//
// Author: Steven Olver
// stevenolver@gmail.com
//
// Date: 17th February 2011
//
// Description: Randomizes translate, rotate and scale transforms
// randomly between editable minimum and maximum values.
// Also capable of switching between absolute and
// relative transforms.
//
// Usage: Run script from script editor or shelf. Select objects
// and tick checkboxes for transforms you wish to apply to.
// Input min and max values for the transforms and select
// absolute or relative, then press ok. The window will
// retain so you can edit values or hit ok again to
// randomize selected transforms again.
//
// (C) Copyright Steven Olver 2011
//
//------------------------------------------------------------------------------//



global proc SMO_RandomizeXForm()
{
//Delete and define window
if ( `window -exists SMO_RandomizeXFormWindow` )
{
deleteUI SMO_RandomizeXFormWindow;
}
window -t "SMO_RandomizeXForm" -rtf true SMO_RandomizeXFormWindow;

//Define layout elements
formLayout -numberOfDivisions 425 SMO_RandomizeXForm_Form;

text -l "X Axis" XAxis;
text -l "Min" XMin;
text -l "Max" XMax;

text -l "Y Axis" YAxis;
text -l "Min" YMin;
text -l "Max" YMax;

text -l "Z Axis" ZAxis;
text -l "Min" ZMin;
text -l "Max" ZMax;

text "Translate";

floatField -w 50 TranslateXMin;
floatField -w 50 TranslateXMax;
checkBox -l "" TranslateXCheckBox;

floatField -w 50 TranslateYMin;
floatField -w 50 TranslateYMax;
checkBox -l "" TranslateYCheckBox;

floatField -w 50 TranslateZMin;
floatField -w 50 TranslateZMax;
checkBox -l "" TranslateZCheckBox;


text "Rotate";

floatField -w 50 RotateXMin;
floatField -w 50 RotateXMax;
checkBox -l "" RotateXCheckBox;

floatField -w 50 RotateYMin;
floatField -w 50 RotateYMax;
checkBox -l "" RotateYCheckBox;

floatField -w 50 RotateZMin;
floatField -w 50 RotateZMax;
checkBox -l "" RotateZCheckBox;


text "Scale";

floatField -w 50 ScaleXMin;
floatField -w 50 ScaleXMax;
checkBox -l "" ScaleXCheckBox;

floatField -w 50 ScaleYMin;
floatField -w 50 ScaleYMax;
checkBox -l "" ScaleYCheckBox;

floatField -w 50 ScaleZMin;
floatField -w 50 ScaleZMax;
checkBox -l "" ScaleZCheckBox;



radioCollection;
radioButton -sl "Absolute";
radioButton "Relative";

button -label "OK" -command "executeSMO_RandomizeXForm" OKButton;

//Defining element positions
formLayout -edit


//Text
-af XAxis "top" 10
-af XAxis "left" 135

-af XMin "top" 25
-af XMin "left" 112

-af XMax "top" 25
-af XMax "left" 170


-af YAxis "top" 10
-af YAxis "left" 285

-af YMin "top" 25
-af YMin "left" 262

-af YMax "top" 25
-af YMax "left" 320


-af ZAxis "top" 10
-af ZAxis "left" 435

-af ZMin "top" 25
-af ZMin "left" 412

-af ZMax "top" 25
-af ZMax "left" 470


//Translate Controls
-af Translate "top" 43
-af Translate "left" 10

-af TranslateXMin "top" 40
-af TranslateXMin "left" 95

-af TranslateXMax "top" 40
-af TranslateXMax "left" 155

-af TranslateXCheckBox "top" 44
-af TranslateXCheckBox "left" 75


-af TranslateYMin "top" 40
-af TranslateYMin "left" 245

-af TranslateYMax "top" 40
-af TranslateYMax "left" 305

-af TranslateYCheckBox "top" 44
-af TranslateYCheckBox "left" 225


-af TranslateZMin "top" 40
-af TranslateZMin "left" 395

-af TranslateZMax "top" 40
-af TranslateZMax "left" 455

-af TranslateZCheckBox "top" 44
-af TranslateZCheckBox "left" 375


//Rotate Controls
-af Rotate "top" 63
-af Rotate "left" 10

-af RotateXMin "top" 60
-af RotateXMin "left" 95

-af RotateXMax "top" 60
-af RotateXMax "left" 155

-af RotateXCheckBox "top" 64
-af RotateXCheckBox "left" 75


-af RotateYMin "top" 60
-af RotateYMin "left" 245

-af RotateYMax "top" 60
-af RotateYMax "left" 305

-af RotateYCheckBox "top" 64
-af RotateYCheckBox "left" 225


-af RotateZMin "top" 60
-af RotateZMin "left" 395

-af RotateZMax "top" 60
-af RotateZMax "left" 455

-af RotateZCheckBox "top" 64
-af RotateZCheckBox "left" 375


//Scale Controls
-af Scale "top" 83
-af Scale "left" 10

-af ScaleXMin "top" 80
-af ScaleXMin "left" 95

-af ScaleXMax "top" 80
-af ScaleXMax "left" 155

-af ScaleXCheckBox "top" 84
-af ScaleXCheckBox "left" 75


-af ScaleYMin "top" 80
-af ScaleYMin "left" 245

-af ScaleYMax "top" 80
-af ScaleYMax "left" 305

-af ScaleYCheckBox "top" 84
-af ScaleYCheckBox "left" 225


-af ScaleZMin "top" 80
-af ScaleZMin "left" 395

-af ScaleZMax "top" 80
-af ScaleZMax "left" 455

-af ScaleZCheckBox "top" 84
-af ScaleZCheckBox "left" 375


//Radio and Buttons
-af Absolute "top" 105
-af Absolute "left" 75

-af Relative "top" 120
-af Relative "left" 75


-af OKButton "top" 145
-af OKButton "left" 75

SMO_RandomizeXForm_Form;

showWindow SMO_RandomizeXFormWindow;
}





// Proc executed when OK button is pressed
proc executeSMO_RandomizeXForm()
{


//Checkbox queries
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;


//Additional checkbox variables for determining conditionals for proc redirection
int $TranslateCheckboxAnyOn = ($TranslateXCheckboxOnOff + $TranslateYCheckboxOnOff + $TranslateZCheckboxOnOff);
int $RotateCheckboxAnyOn = ($RotateXCheckboxOnOff + $RotateYCheckboxOnOff + $RotateZCheckboxOnOff);
int $ScaleCheckboxAnyOn = ($ScaleXCheckboxOnOff + $ScaleYCheckboxOnOff + $ScaleZCheckboxOnOff);


//Conditionals to redirect to procs if checkboxes are ticked

//TranslateProcs
if ($TranslateCheckboxAnyOn > 0)
{
TranslateProc;
}



//RotateProcs
if ($RotateCheckboxAnyOn > 0)
{
RotateProc;
}



//ScaleProcs
if ($ScaleCheckboxAnyOn > 0)
{
ScaleProc;
}


}





//Main transform execution procs and loops. Switch/case is used to determine
//absolute or relative. If else loop used to query the checkbox
//variables and do the transform if yes, do nothing if no.

//Translate Execute
proc TranslateProc()
{


//Checkbox Queries again
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

//floatFieldQueries
float $InputTransXMin = `floatField -q -v TranslateXMin`;
float $InputTransXMax = `floatField -q -v TranslateXMax`;

float $InputTransYMin = `floatField -q -v TranslateYMin`;
float $InputTransYMax = `floatField -q -v TranslateYMax`;

float $InputTransZMin = `floatField -q -v TranslateZMin`;
float $InputTransZMax = `floatField -q -v TranslateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Translate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $TranslateRandom[] = `getAttr ($objects+".translate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
xform -a -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
case false:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
else
{
$TranslateRandom[0] = 0;
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
else
{
$TranslateRandom[1] = 0;
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
else
{
$TranslateRandom[2] = 0;
}
xform -r -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
}

}

}





//Rotate Execute
proc RotateProc()
{


//Checkbox Queries again
int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

//floatFieldQueries
float $InputRotateXMin = `floatField -q -v RotateXMin`;
float $InputRotateXMax = `floatField -q -v RotateXMax`;
float $InputRotateYMin = `floatField -q -v RotateYMin`;
float $InputRotateYMax = `floatField -q -v RotateYMax`;
float $InputRotateZMin = `floatField -q -v RotateZMin`;
float $InputRotateZMax = `floatField -q -v RotateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Rotate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $RotateRandom[] = `getAttr ($objects+".rotate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
xform -a -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
case false:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
else
{
$RotateRandom[0] = 0;
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
else
{
$RotateRandom[1] = 0;
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
else
{
$RotateRandom[2] = 0;
}
xform -r -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
}

}

}





//ScaleExecute
proc ScaleProc()
{


//Checkbox Queries again
int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;

//floatFieldQueries
float $InputScaleXMin = `floatField -q -v ScaleXMin`;
float $InputScaleXMax = `floatField -q -v ScaleXMax`;
float $InputScaleYMin = `floatField -q -v ScaleYMin`;
float $InputScaleYMax = `floatField -q -v ScaleYMax`;
float $InputScaleZMin = `floatField -q -v ScaleZMin`;
float $InputScaleZMax = `floatField -q -v ScaleZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Scale Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $ScaleRandom[] = `getAttr ($objects+".scale")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
xform -a -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
case false:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
else
{
$ScaleRandom[0] = 1;
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
else
{
$ScaleRandom[1] = 1;
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
else
{
$ScaleRandom[2] = 1;
}
xform -r -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
}

}

}
//End

edit: k it's a hell of a lot faster! :D

Diamant
02-17-2011, 08:37 AM
here is your conditional statement.. you over complicated it.

if ($transX == 1 || $transY == 1 || $transZ == 1)
translateProc;


just to see what it would take to not call similar lines of code with slight differences, I took the same base code that goleafsgo told you to rewrite and wrote it without any reuse... its a bit more complicated and I don't actually think I'd do this for pure readability.. but I figured I'd post it since it could be informative to some.. and it was a fun little exercise to try..

here is your translateProc, it can be modified too to incorporate rotation and scale as well. also the variables and checkbox names are different.. but it should make sense as to what they are.. I can explain further if this doesn't make sense..

-Rich


string $objs[] = `ls -sl`;
string $obj;
for ($obj in $objs)
{
string $aRand[] = {"xCheckBox", "xInputMin", "xInputMax", "yCheckBox", "yInputMinimum", "yInputMin", "zCheckBox", "zInputMin", "zInputMax"};
float $randVals[] = `getAttr ($obj + ".translate")`;

for ($i=0; $i < size($aRand); $i+=3)
{
if (`checkBox -q -v $aRand[$i]`)
{
float $lRand = `floatField -q -v $aRand[$i + 1]`;
float $hRand = `floatField -q -v $aRand[$i + 2]`;
$randVals[size($aRand) % ($i + 1)] = rand ($lRand, $hRand);
}
}

xform -a -t $randVals[0] $randVals[1] $randVals[2] $obj;
}

Freshfromthegrave
02-17-2011, 09:17 AM
hellz rich i could never have thought of that at this stage xD i can kinda follow it :) but i think i'm gonna leave it as is for the moment i think i'm pretty happy with how the script works and how fast it is, as well as what i've learnt making it ;)

Freshfromthegrave
02-17-2011, 10:06 AM
oh hang on... all the procs need to be global otherwise it doesn't work when you source it?

Freshfromthegrave
02-17-2011, 01:39 PM
ok it works with all procs being global but is it really necessary to have them all global?

//------------------------------------------------------------------------------//
// Script: SMO_RandomizeXForm.mel
//
// Version: 1.0
//
// Author: Steven Olver
// stevenolver@gmail.com
//
// Date: 17th February 2011
//
// Description: Randomizes translate, rotate and scale transforms
// randomly between editable minimum and maximum values.
// Also capable of switching between absolute and
// relative transforms.
//
// Installation: Place SMO_RandomizeXForm.mel and SMO_RandomizeXFormShelfButton.mel
// in your Documents\maya\2011-x64\scripts folder. Load the
// SMO_RandomizeXFormShelfButton.mel into script editor, select
// the text and middle mouse drag it to your shelf.
//
// Usage: Select objects and tick checkboxes for transforms you
// wish to apply to. Input min and max values for the
// transforms and select absolute or relative, then press ok.
// The window will retain so you can edit values or hit ok
// again to randomize selected transforms again.
//
// (C) Copyright Steven Olver 2011
//
//------------------------------------------------------------------------------//



global proc SMO_RandomizeXForm()
{
//Delete and define window
if ( `window -exists SMO_RandomizeXFormWindow` )
{
deleteUI SMO_RandomizeXFormWindow;
}
window -t "SMO_RandomizeXForm" -rtf true SMO_RandomizeXFormWindow;

//Define layout elements
formLayout -numberOfDivisions 425 SMO_RandomizeXForm_Form;

text -l "X Axis" XAxis;
text -l "Min" XMin;
text -l "Max" XMax;

text -l "Y Axis" YAxis;
text -l "Min" YMin;
text -l "Max" YMax;

text -l "Z Axis" ZAxis;
text -l "Min" ZMin;
text -l "Max" ZMax;

text "Translate";

floatField -w 50 TranslateXMin;
floatField -w 50 TranslateXMax;
checkBox -l "" TranslateXCheckBox;

floatField -w 50 TranslateYMin;
floatField -w 50 TranslateYMax;
checkBox -l "" TranslateYCheckBox;

floatField -w 50 TranslateZMin;
floatField -w 50 TranslateZMax;
checkBox -l "" TranslateZCheckBox;


text "Rotate";

floatField -w 50 RotateXMin;
floatField -w 50 RotateXMax;
checkBox -l "" RotateXCheckBox;

floatField -w 50 RotateYMin;
floatField -w 50 RotateYMax;
checkBox -l "" RotateYCheckBox;

floatField -w 50 RotateZMin;
floatField -w 50 RotateZMax;
checkBox -l "" RotateZCheckBox;


text "Scale";

floatField -w 50 ScaleXMin;
floatField -w 50 ScaleXMax;
checkBox -l "" ScaleXCheckBox;

floatField -w 50 ScaleYMin;
floatField -w 50 ScaleYMax;
checkBox -l "" ScaleYCheckBox;

floatField -w 50 ScaleZMin;
floatField -w 50 ScaleZMax;
checkBox -l "" ScaleZCheckBox;



radioCollection;
radioButton -sl "Absolute";
radioButton "Relative";

button -label "OK" -command "executeSMO_RandomizeXForm" OKButton;

//Defining element positions
formLayout -edit


//Text
-af XAxis "top" 10
-af XAxis "left" 135

-af XMin "top" 25
-af XMin "left" 112

-af XMax "top" 25
-af XMax "left" 170


-af YAxis "top" 10
-af YAxis "left" 285

-af YMin "top" 25
-af YMin "left" 262

-af YMax "top" 25
-af YMax "left" 320


-af ZAxis "top" 10
-af ZAxis "left" 435

-af ZMin "top" 25
-af ZMin "left" 412

-af ZMax "top" 25
-af ZMax "left" 470


//Translate Controls
-af Translate "top" 43
-af Translate "left" 10

-af TranslateXMin "top" 40
-af TranslateXMin "left" 95

-af TranslateXMax "top" 40
-af TranslateXMax "left" 155

-af TranslateXCheckBox "top" 44
-af TranslateXCheckBox "left" 75


-af TranslateYMin "top" 40
-af TranslateYMin "left" 245

-af TranslateYMax "top" 40
-af TranslateYMax "left" 305

-af TranslateYCheckBox "top" 44
-af TranslateYCheckBox "left" 225


-af TranslateZMin "top" 40
-af TranslateZMin "left" 395

-af TranslateZMax "top" 40
-af TranslateZMax "left" 455

-af TranslateZCheckBox "top" 44
-af TranslateZCheckBox "left" 375


//Rotate Controls
-af Rotate "top" 63
-af Rotate "left" 10

-af RotateXMin "top" 60
-af RotateXMin "left" 95

-af RotateXMax "top" 60
-af RotateXMax "left" 155

-af RotateXCheckBox "top" 64
-af RotateXCheckBox "left" 75


-af RotateYMin "top" 60
-af RotateYMin "left" 245

-af RotateYMax "top" 60
-af RotateYMax "left" 305

-af RotateYCheckBox "top" 64
-af RotateYCheckBox "left" 225


-af RotateZMin "top" 60
-af RotateZMin "left" 395

-af RotateZMax "top" 60
-af RotateZMax "left" 455

-af RotateZCheckBox "top" 64
-af RotateZCheckBox "left" 375


//Scale Controls
-af Scale "top" 83
-af Scale "left" 10

-af ScaleXMin "top" 80
-af ScaleXMin "left" 95

-af ScaleXMax "top" 80
-af ScaleXMax "left" 155

-af ScaleXCheckBox "top" 84
-af ScaleXCheckBox "left" 75


-af ScaleYMin "top" 80
-af ScaleYMin "left" 245

-af ScaleYMax "top" 80
-af ScaleYMax "left" 305

-af ScaleYCheckBox "top" 84
-af ScaleYCheckBox "left" 225


-af ScaleZMin "top" 80
-af ScaleZMin "left" 395

-af ScaleZMax "top" 80
-af ScaleZMax "left" 455

-af ScaleZCheckBox "top" 84
-af ScaleZCheckBox "left" 375


//Radio and Buttons
-af Absolute "top" 105
-af Absolute "left" 75

-af Relative "top" 120
-af Relative "left" 75


-af OKButton "top" 145
-af OKButton "left" 75

SMO_RandomizeXForm_Form;

showWindow SMO_RandomizeXFormWindow;
}





// Proc executed when OK button is pressed
global proc executeSMO_RandomizeXForm()
{


//Checkbox queries
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;


//Additional checkbox variables for determining conditionals for proc redirection
int $TranslateCheckboxAnyOn = ($TranslateXCheckboxOnOff + $TranslateYCheckboxOnOff + $TranslateZCheckboxOnOff);
int $RotateCheckboxAnyOn = ($RotateXCheckboxOnOff + $RotateYCheckboxOnOff + $RotateZCheckboxOnOff);
int $ScaleCheckboxAnyOn = ($ScaleXCheckboxOnOff + $ScaleYCheckboxOnOff + $ScaleZCheckboxOnOff);


//Conditionals to redirect to procs if checkboxes are ticked

//TranslateProcs
if ($TranslateCheckboxAnyOn > 0)
{
SMO_RandomizeXForm_TranslateProc;
}



//RotateProcs
if ($RotateCheckboxAnyOn > 0)
{
SMO_RandomizeXForm_RotateProc;
}



//ScaleProcs
if ($ScaleCheckboxAnyOn > 0)
{
SMO_RandomizeXForm_ScaleProc;
}



}





//Main transform execution procs and loops. Switch/case is used to determine
//absolute or relative. If else loop used to query the checkbox
//variables and do the transform if yes, do nothing if no.

//Translate Execute
global proc SMO_RandomizeXForm_TranslateProc()
{


//Checkbox Queries again
int $TranslateXCheckboxOnOff = `checkBox -q -v TranslateXCheckBox`;
int $TranslateYCheckboxOnOff = `checkBox -q -v TranslateYCheckBox`;
int $TranslateZCheckboxOnOff = `checkBox -q -v TranslateZCheckBox`;

//floatFieldQueries
float $InputTransXMin = `floatField -q -v TranslateXMin`;
float $InputTransXMax = `floatField -q -v TranslateXMax`;

float $InputTransYMin = `floatField -q -v TranslateYMin`;
float $InputTransYMax = `floatField -q -v TranslateYMax`;

float $InputTransZMin = `floatField -q -v TranslateZMin`;
float $InputTransZMax = `floatField -q -v TranslateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Translate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $TranslateRandom[] = `getAttr ($objects+".translate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
xform -a -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
case false:
if ($TranslateXCheckboxOnOff == 1)
{
$TranslateRandom[0] = rand ($InputTransXMin,$InputTransXMax);
}
else
{
$TranslateRandom[0] = 0;
}
if ($TranslateYCheckboxOnOff == 1)
{
$TranslateRandom[1] = rand ($InputTransYMin,$InputTransYMax);
}
else
{
$TranslateRandom[1] = 0;
}
if ($TranslateZCheckboxOnOff == 1)
{
$TranslateRandom[2] = rand ($InputTransZMin,$InputTransZMax);
}
else
{
$TranslateRandom[2] = 0;
}
xform -r -t $TranslateRandom[0] $TranslateRandom[1] $TranslateRandom[2] $objects;
break;
}

}

}





//Rotate Execute
global proc SMO_RandomizeXForm_RotateProc()
{


//Checkbox Queries again
int $RotateXCheckboxOnOff = `checkBox -q -v RotateXCheckBox`;
int $RotateYCheckboxOnOff = `checkBox -q -v RotateYCheckBox`;
int $RotateZCheckboxOnOff = `checkBox -q -v RotateZCheckBox`;

//floatFieldQueries
float $InputRotateXMin = `floatField -q -v RotateXMin`;
float $InputRotateXMax = `floatField -q -v RotateXMax`;
float $InputRotateYMin = `floatField -q -v RotateYMin`;
float $InputRotateYMax = `floatField -q -v RotateYMax`;
float $InputRotateZMin = `floatField -q -v RotateZMin`;
float $InputRotateZMax = `floatField -q -v RotateZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Rotate Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $RotateRandom[] = `getAttr ($objects+".rotate")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
xform -a -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
case false:
if ($RotateXCheckboxOnOff == 1)
{
$RotateRandom[0] = rand ($InputRotateXMin,$InputRotateXMax);
}
else
{
$RotateRandom[0] = 0;
}
if ($RotateYCheckboxOnOff == 1)
{
$RotateRandom[1] = rand ($InputRotateYMin,$InputRotateYMax);
}
else
{
$RotateRandom[1] = 0;
}
if ($RotateZCheckboxOnOff == 1)
{
$RotateRandom[2] = rand ($InputRotateZMin,$InputRotateZMax);
}
else
{
$RotateRandom[2] = 0;
}
xform -r -ro $RotateRandom[0] $RotateRandom[1] $RotateRandom[2] $objects;
break;
}

}

}





//ScaleExecute
global proc SMO_RandomizeXForm_ScaleProc()
{


//Checkbox Queries again
int $ScaleXCheckboxOnOff = `checkBox -q -v ScaleXCheckBox`;
int $ScaleYCheckboxOnOff = `checkBox -q -v ScaleYCheckBox`;
int $ScaleZCheckboxOnOff = `checkBox -q -v ScaleZCheckBox`;

//floatFieldQueries
float $InputScaleXMin = `floatField -q -v ScaleXMin`;
float $InputScaleXMax = `floatField -q -v ScaleXMax`;
float $InputScaleYMin = `floatField -q -v ScaleYMin`;
float $InputScaleYMax = `floatField -q -v ScaleYMax`;
float $InputScaleZMin = `floatField -q -v ScaleZMin`;
float $InputScaleZMax = `floatField -q -v ScaleZMax`;

//RadioButton Query
int $RadioButtonAbsolute = `radioButton -q -sl Absolute`;


//Main Scale Loop
string $selectedObjects[] = `ls -sl`;
for ($objects in $selectedObjects)
{


//check current object attributes
float $ScaleRandom[] = `getAttr ($objects+".scale")`;


//Check radiobutton and use switch/case to determine absolute and relative
//If checkboxes are ticked change the string to the floatField value
switch($RadioButtonAbsolute)
{
case true:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
xform -a -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
case false:
if ($ScaleXCheckboxOnOff == 1)
{
$ScaleRandom[0] = rand ($InputScaleXMin,$InputScaleXMax);
}
else
{
$ScaleRandom[0] = 1;
}
if ($ScaleYCheckboxOnOff == 1)
{
$ScaleRandom[1] = rand ($InputScaleYMin,$InputScaleYMax);
}
else
{
$ScaleRandom[1] = 1;
}
if ($ScaleZCheckboxOnOff == 1)
{
$ScaleRandom[2] = rand ($InputScaleZMin,$InputScaleZMax);
}
else
{
$ScaleRandom[2] = 1;
}
xform -r -s $ScaleRandom[0] $ScaleRandom[1] $ScaleRandom[2] $objects;
break;
}

}

}
//End

edit: oh fixed :) gotta move the local procs above the global ones ^^ kind of a weird rule that...

ewerybody
02-18-2011, 12:56 PM
All procs that are called from outside the mel file have to be global.

So If you create a UI in the script, you created an external caller too!
But a proc thats executed from a button can call other local procs of course! Because its inside the script again. (yep: IF they are above the call location in the script. I usuall put the main ui proc top, then locals and then the other stuff)

Sourcing and hashing MEL is quite a mystic thing anyway...
Executing from the Script Editor, Sourcing bla.mel and having the file hashed (loaded up automatically on startup without an explicit source call) are 3 diffent things.

:rolleyes: am I right? ;D correct me if its bs.

CGTalk Moderation
02-18-2011, 12:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.