//Name: acScaler.mel //Author: Allen Curtis //Email: allenatl@allen3d.com //Date: May 20, 2007 //Revised: May 23, 2007 //Description: Dialog box for proportional scaling. //Details: //Proportional button scales x, y, and z values. //Use in object mode. Select an object before opening window. //Proportional Scale changes do not take effect until the Apply button is pressed. //Reset Scale button resets scale to 1.0. Reset before entering a Desired Size. //Freeze button makes the current size the new 1.0 scale. //Check the Centimeters checkbox to scale to desired size in centimeters. //Uncheck the Centimeters checkbox to scale to desired size in inches. //Press the Prop. Scale button to preview proportional size change in the Inches //or Centimeters textfields. //Press the Apply button to apply the scale to the selected object. //The selected object is scaled on the axis selected and the other two axes are scaled proportionately. //Update button shows what is selected in a label at top of the acScaler window. //Press the Update button to verify the current selection. //Edit Sliders button adjusts sliders maximum, minimum, and step values. //Undoing doesn't update bounding box fields. Click the update button after undoing. global string $getSelected[]; global proc acScaler(){ $getSelected=`ls -sl`; if(size(`filterExpand -sm 9 -sm 10 -sm 12 -sm 68 -sm 72`)>0){ if(`window -exists acScaleWindow`) deleteUI acScaleWindow; window -widthHeight 300 200 -title "acScaler" -rtf true acScaleWindow; //This outer formLayout was only added for better alignment of bottom and top elements //Using attachForm with a larger offset centered the upper ColumnLayout better. string $outerLayout = `formLayout -numberOfDivisions 100`; columnLayout -columnAttach "left" 10 -columnOffset "both" 5 -rs 5 ColumnLayout; //Controls for viewing position of current selection. text -label "Selection" SelectionLabel; text -edit -label ("Selection: " + $getSelected[0] + " :1 of " + size($getSelected) + " selected") SelectionLabel; floatFieldGrp -numberOfFields 3 -label "Size in Centimeters:" -v1 1.0 -v2 1.0 -v3 1.0 -pre 6 -en false boxCtField; floatFieldGrp -numberOfFields 3 -label "Size in Inches:" -v1 1.0 -v2 1.0 -v3 1.0 -pre 6 -en true boxInchField; floatFieldGrp -numberOfFields 3 -label "BoundingBoxMin:" -v1 0.0 -v2 0.0 -v3 0.0 -pre 6 -en false boxMinField; floatFieldGrp -numberOfFields 3 -label "BoundingBoxMax:" -v1 0.0 -v2 0.0 -v3 0.0 -pre 6 -en false boxMaxField; //The -at flag determines what attributes are affected by sliders. attrFieldSliderGrp -min .01 -max 4 -step 0.001 -pre 6 -at ($getSelected[0] +".sx")-cc "showBBox" xSlider; attrFieldSliderGrp -min .01 -max 4 -step 0.001 -pre 6 -at ($getSelected[0] + ".sy")-cc "showBBox" ySlider; attrFieldSliderGrp -min .01 -max 4 -step 0.001 -pre 6 -at ($getSelected[0] + ".sz") -cc "showBBox" zSlider; floatFieldGrp -nf 1 -l "Proportional Scale:" -v1 1.0 -pre 6 propScaleField; //Layout nested inside another layout. rowLayout -numberOfColumns 7 MainRowLayout; columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent MainRowLayout Column1;//Spacing columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent MainRowLayout Column2; button -label "Update" -c "showBBox" UpdateButton; columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent MainRowLayout Column3; button -label "Apply" -c "acPropScale" PropButton; columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent MainRowLayout Column4; button -label "Close" -c "deleteUI acScaleWindow" ExitButton; columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent MainRowLayout Column5;//Spacing columnLayout -columnAttach "both" 5 -rowSpacing 10 -parent ColumnLayout CheckBoxColumn; checkBox -label "Centimeters" -value 0 checkCentimeters; string $form = `formLayout -numberOfDivisions 100 -parent $outerLayout`; columnLayout -adjustableColumn false -parent $form ScaledColumnLayout; floatFieldGrp -nf 1 -l "Desired Size:" -v1 1.0 -pre 6 scaledSizeField; columnLayout -adjustableColumn false -parent $form SizeButtonColumnLayout; button -label "Prop. Scale" -align "center" -width 80 -c "desiredScaleSize" SizeButton; columnLayout -adjustableColumn false -parent $form ResetButtonColumnLayout; button -label "Reset Scale" -align "center" -width 80 -c "resetScaleToOne" ResetButton; columnLayout -adjustableColumn false -parent $form FreezeButtonColumnLayout; button -label "Freeze Scale" -align "center" -width 80 -c "makeIdentity -apply true -t 0 -r 0 -s 1 -n 0" FreezeButton; columnLayout -adjustableColumn false -parent $form AxisColumnLayout; radioButtonGrp -numberOfRadioButtons 3 -columnAlign 1 "left" -columnWidth 1 60 -columnWidth 2 80 -label "Axis:" -labelArray3 "x" "y" "z" -sl 2 radioScaledSize; columnLayout -adjustableColumn false -parent $form EditSliderLayout; floatFieldGrp -nf 3 -l "Sliders Min/Max/Step:" -v1 .01 -v2 4 -v3 .001 -pre 6 editSlidersField; columnLayout -adjustableColumn false -parent $form SliderButtonLayout; button -label "Edit Sliders" -c "editSliders" SliderButton; formLayout -edit -attachForm ScaledColumnLayout "top" 5 -attachForm ScaledColumnLayout "left" 5 -attachControl ScaledColumnLayout "bottom" 10 AxisColumnLayout -attachOppositeControl SizeButtonColumnLayout "top" 5 ScaledColumnLayout -attachControl SizeButtonColumnLayout "left" 10 ScaledColumnLayout -attachControl SizeButtonColumnLayout "bottom" 10 AxisColumnLayout -attachOppositeControl ResetButtonColumnLayout "top" 5 ScaledColumnLayout -attachControl ResetButtonColumnLayout "left" 5 SizeButtonColumnLayout -attachControl ResetButtonColumnLayout "bottom" 10 AxisColumnLayout -attachOppositeControl FreezeButtonColumnLayout "top" 5 ScaledColumnLayout -attachControl FreezeButtonColumnLayout "left" 5 ResetButtonColumnLayout -attachControl FreezeButtonColumnLayout "bottom" 10 AxisColumnLayout -attachNone AxisColumnLayout "top" -attachForm AxisColumnLayout "right" 15 -attachControl AxisColumnLayout "bottom" 10 EditSliderLayout -attachNone EditSliderLayout "top" -attachForm EditSliderLayout "left" 5 -attachForm EditSliderLayout "bottom" 10 -attachNone SliderButtonLayout "top" -attachForm SliderButtonLayout "right" 5 -attachForm SliderButtonLayout "bottom" 10 $form; formLayout -edit -attachForm ColumnLayout "top" 5 -attachForm ColumnLayout "left" 28 -attachForm $form "bottom" 5 -attachForm $form "left" 5 $outerLayout; window -edit -widthHeight 538 520 acScaleWindow; showWindow acScaleWindow; }else{ confirmDialog -title "acScaler: Selection Type" -message "Select a Polygon, Subdiv, or NURBS Object before opening acScaler." -button "OK"; }//end else } global proc acPropScale(){ float $getValue = `floatFieldGrp -q -v1 propScaleField`; scale $getValue $getValue $getValue ; showBBox; } global proc showBBox(){ $getSelected =`ls -sl`; if(size(`filterExpand -sm 9 -sm 10 -sm 12 -sm 68 -sm 72`)>0){ string $attr = $getSelected[0] + ".boundingBoxSize"; float $value[]= `getAttr $attr`; float $selNumber = size($getSelected); if ($selNumber>1){ text -edit -label ("Multiple selections: " + $getSelected[0] + " :1 of " + $selNumber + ". Unexpected results possible.") SelectionLabel; }else{ text -edit -label ("Selection: " + $getSelected[0] + " :1 of " + $selNumber + " selected") SelectionLabel; } floatFieldGrp -edit -v1 $value[0] boxCtField; floatFieldGrp -edit -v2 $value[1] boxCtField; floatFieldGrp -edit -v3 $value[2] boxCtField; $attr = $getSelected[0] + ".boundingBoxMax"; float $conversion = 0.3937; float $inch= $value[0] * $conversion; floatFieldGrp -edit -v1 $inch boxInchField; $inch= $value[1] * $conversion; floatFieldGrp -edit -v2 $inch boxInchField; $inch= $value[2] * $conversion; floatFieldGrp -edit -v3 $inch boxInchField; $attr = $getSelected[0] + ".boundingBoxMin"; $value = `getAttr $attr`; floatFieldGrp -edit -v1 $value[0] boxMinField; floatFieldGrp -edit -v2 $value[1] boxMinField; floatFieldGrp -edit -v3 $value[2] boxMinField; $attr = $getSelected[0] + ".boundingBoxMax"; $value = `getAttr $attr`; floatFieldGrp -edit -v1 $value[0] boxMaxField; floatFieldGrp -edit -v2 $value[1] boxMaxField; floatFieldGrp -edit -v3 $value[2] boxMaxField; float $editMin = `floatFieldGrp -q -v1 editSlidersField`; float $editMax = `floatFieldGrp -q -v2 editSlidersField`; float $editStep = `floatFieldGrp -q -v3 editSlidersField`; //Update sliders when a new selection is made. attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] +".sx") xSlider; attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] + ".sy") ySlider; attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] + ".sz") zSlider; }else{ confirmDialog -title "acScaler: Selection Type" -message "Select Polygon, Subdiv, or NURBS Object Type." -button "OK"; }//end else }//end proc global proc editSliders(){ $getSelected =`ls -sl`; if(size(`filterExpand -sm 9 -sm 10 -sm 12 -sm 68 -sm 72`)>0){ float $editMin = `floatFieldGrp -q -v1 editSlidersField`; float $editMax = `floatFieldGrp -q -v2 editSlidersField`; float $editStep = `floatFieldGrp -q -v3 editSlidersField`; attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] +".sx") xSlider; attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] + ".sy") ySlider; attrFieldSliderGrp -edit -min $editMin -max $editMax -step $editStep -at ($getSelected[0] + ".sz") zSlider; }else{ confirmDialog -title "acScaler: Selection Type" -message "Select Polygon, Subdiv, or NURBS Object Type." -button "OK"; }//end else } global proc desiredScaleSize(){ float $getXValue; float $getYValue; float $getZValue; float $setDesiredValue = `floatFieldGrp -q -v1 scaledSizeField`; float $getProp = `floatFieldGrp -q -v1 propScaleField`; int $inchOrMetric=`checkBox -query -value checkCentimeters`; if($inchOrMetric==0){ floatFieldGrp -edit -en false boxCtField; floatFieldGrp -edit -en true boxInchField; $getXValue = `floatFieldGrp -q -v1 boxInchField`; $getYValue = `floatFieldGrp -q -v2 boxInchField`; $getZValue = `floatFieldGrp -q -v3 boxInchField`; }else if($inchOrMetric==1){ floatFieldGrp -edit -en true boxCtField; floatFieldGrp -edit -en false boxInchField; $getXValue = `floatFieldGrp -q -v1 boxCtField`; $getYValue = `floatFieldGrp -q -v2 boxCtField`; $getZValue = `floatFieldGrp -q -v3 boxCtField`; } int $radioAxis = `radioButtonGrp -q -sl radioScaledSize`; float $percent; float $setXSize; float $setYSize; float $setZSize; //x axis selected if(($radioAxis==1) && ($getProp==1.0)){ if($getXValue==0){//inner if else confirmDialog -title "acScaler: Scaling Message" -message "Size on X axis is 0. Select another axis for desired size." -button "OK";}else{ $percent = $setDesiredValue/$getXValue; $setYSize = $getYValue * $percent; $setZSize = $getZValue * $percent; string $changePercent = `floatFieldGrp -edit -v1 $percent propScaleField`; if($inchOrMetric==0){ //nested if floatFieldGrp -edit -v1 $setDesiredValue boxInchField; floatFieldGrp -edit -v2 $setYSize boxInchField; floatFieldGrp -edit -v3 $setZSize boxInchField; }else if($inchOrMetric==1){ floatFieldGrp -edit -v1 $setDesiredValue boxCtField; floatFieldGrp -edit -v2 $setYSize boxCtField; floatFieldGrp -edit -v3 $setZSize boxCtField; }//nested if ends }//inner if else ends //y axix selected }else if(($radioAxis==2) && ($getProp==1.0)){ if($getYValue==0){//inner if else confirmDialog -title "acScaler: Scaling Message" -message "Size on Y axis is 0. Select another axis for desired size." -button "OK";}else{ $percent = $setDesiredValue/$getYValue; $setXSize = $getXValue * $percent; $setZSize = $getZValue * $percent; string $changePercent = `floatFieldGrp -edit -v1 $percent propScaleField`; if($inchOrMetric==0){//nested if floatFieldGrp -edit -v1 $setXSize boxInchField; floatFieldGrp -edit -v2 $setDesiredValue boxInchField; floatFieldGrp -edit -v3 $setZSize boxInchField; }else if($inchOrMetric==1){ floatFieldGrp -edit -v1 $setXSize boxCtField; floatFieldGrp -edit -v2 $setDesiredValue boxCtField; floatFieldGrp -edit -v3 $setZSize boxCtField; }//nested if ends }//inner if else ends //z axis selected }else if(($radioAxis==3) && ($getProp==1.0)){ if($getZValue==0){//inner if else confirmDialog -title "acScaler: Scaling Message" -message "Size on Z axis is 0. Select another axis for desired size." -button "OK";}else{ $percent = $setDesiredValue/$getZValue; $setXSize = $getXValue * $percent; $setYSize = $getYValue * $percent; string $changePercent = `floatFieldGrp -edit -v1 $percent propScaleField`; if($inchOrMetric==0){//nested if floatFieldGrp -edit -v1 $setXSize boxInchField; floatFieldGrp -edit -v2 $setYSize boxInchField; floatFieldGrp -edit -v3 $setDesiredValue boxInchField; }else if($inchOrMetric==1){ floatFieldGrp -edit -v1 $setXSize boxCtField; floatFieldGrp -edit -v2 $setYSize boxCtField; floatFieldGrp -edit -v3 $setDesiredValue boxCtField; }//nested if ends }//inner if else ends }else{ confirmDialog -title "acScaler: Scaling Message" -message "Reset Scale before entering desired size." -button "OK"; } } global proc resetScaleToOne(){ floatFieldGrp -edit -v1 1.0 propScaleField; acPropScale; }