RSS FEED

Scale to fit

In a reply to a question posted at Maxarea :: Zmena rozmerov objektu udavanim cisiel about the possibility to scale the objects to match given dimensions I made a small script. It allows you to pick an object and change the dimension in either world coord system or in local one. The main purpose is to help with rescaling collapsed or imported objects (i.e. editable meshes or polys) to exact sizes.
try destroyDialog dialog_scaleToValue catch()
rollout dialog_scaleToValue "Scale to Value" width:100
(
    spinner spnDimensionX "X: " width:90 offset:[-15,0]
    spinner spnDimensionY "Y: " width:90 offset:[-15,0]
    spinner spnDimensionZ "Z: " width:90 offset:[-15,0]

    checkButton chbLocal "Use Local Axes"

    fn updateSpinners = if selection.count == 1 do
    (
        local obj = selection[1]
        local diff = if NOT chbLocal.checked then (obj.max - obj.min)
            else (in coordsys obj ((nodeLocalBoundingBox obj)[2] - (nodeLocalBoundingBox obj)[1])) * obj.scale

        for s = 1 to 3 do dialog_scaleToValue.controls[s].value = diff[s]
    )

    fn scaleToVal obj val axis abs =
    (
        local diff = if abs then (obj.max - obj.min)
            else (in coordsys obj ((nodeLocalBoundingBox obj)[2] - (nodeLocalBoundingBox obj)[1])) * obj.scale

        local point_3 = [1,1,1]
        local scale_ratio = val/diff[axis]
        point_3[axis] = scale_ratio
        if abs then scale obj point_3
            else in coordsys obj scale obj point_3
    )

    fn doTheScale val axis =
        with undo label:"Scale to Value" on
            if selection.count == 1 AND NOT isDeleted selection[1] do
                scaleToVal selection[1] val axis (NOT chbLocal.checked)

    on dialog_scaleToValue open do
    (
        callbacks.addScript #selectionSetChanged "dialog_scaleToValue.updateSpinners()" id:#scaleToValue
        updateSpinners()
    )

    on spnDimensionX changed val do doTheScale val 1
    on spnDimensionY changed val do doTheScale val 2
    on spnDimensionZ changed val do doTheScale val 3

    on chbLocal changed state do updateSpinners()

    on dialog_scaleToValue closed do callbacks.removeScripts #selectionSetChanged id:#scaleToValue
)
createDialog dialog_scaleToValue
USAGE: Run the script, either pick an object or use the one that was already selected. Change the values to fit your needs. If Use Local Axes is checked, all the changes will be done in objects' localspace, otherwise in the world space. All the changes are relative to object's pivot. If you select another object, the spinners will be populated with its dimensions instead. Only works on single selections.

Scale to fit interface

DISCLAIMER: All scripts and snippets are provided as is under Creative Commons Zero (public domain, no restrictions) license. The author and this blog cannot be held liable for any loss caused as a result of inaccuracy or error within these web pages. Use at your own risk.

This Post needs Your Comment!

Return to top