Random UVW Map Gizmo Shift

Recently I've been asked by a co-worker to write a very simple script to randomly shift UVW Map gizmo of selected objects by an amount in a given range. And that's what it does. I'm open to any suggestion as to how to increase its usefulness, though.

try destroyDialog randomizeUVWdialog catch()
rollout randomizeUVWdialog "Randomize UVW" height:155 width:175
    label lblVectorX "Range X:" pos:[15,7]
    label lblVectorY "Range Y:" pos:[15,25]
    label lblVectorZ "Range Z:" pos:[15,43]

    spinner spnRangeX "\xB1" width:65 range:[-1e9,1e9,0.] scale:1 pos:[100,7]
    spinner spnRangeY "\xB1" width:65 range:[-1e9,1e9,0.] scale:1 pos:[100,25]
    spinner spnRangeZ "\xB1" width:65 range:[-1e9,1e9,0.] scale:1 pos:[100,43]

    checkBox chxLinkSpinners "Use X Range For All" align:#center offset:[0,5]
    radioButtons rbCoords labels:#("World", "Local") offset:[0,7]

    button btnRandomize "RANDOMIZE" offset:[0,7] width:160 height:25

    mapped fn randomizeUvw obj range coord =
        local howManyModifiers = obj.modifiers.count
        for m = howManyModifiers to 1 by -1
            where isKindOf (local objMod = obj.modifiers[m]) Uvwmap do
                if coord then exit with objMod.gizmo.pos += [random -range.x range.x,random -range.y range.y,random -range.z range.z]/obj.scale
                else exit with objMod.gizmo.pos = ((objMod.gizmo.pos * obj.transform) + [random -range.x range.x,random -range.y range.y,random -range.z range.z]) * inverse obj.transform

    on spnRangeX changed val do
        if chxLinkSpinners.checked do
            #(spnRangeY, spnRangeZ).value = val

    on chxLinkSpinners changed state do
        #(spnRangeY, spnRangeZ).enabled = NOT state
        if state do #(spnRangeY, spnRangeZ).value = spnRangeX.value

    on btnRandomize pressed do
        if selection.count == 0 then
            messageBox "Nothing selected!" title:"Error"
            setCommandPanelTaskMode mode:#modify
            with undo label:"Randomize UVW" on randomizeUvw selection [spnRangeX.value,spnRangeY.value,spnRangeZ.value]    (rbCoords.state == 2)
createDialog randomizeUVWdialog

USAGE: Select some objects with UVW Map modifier applied, enter maximum XYZ values in the range input fields and press Randomize. You can choose whether you want the shift to happen in the world coordinate system or local. The units will be always world units, independent on the scale of the object.

Randomize UVW UI

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!


hi, your script is great, i try it on max 2013. but it need that one add the uvwmap modifier one by one.

is there a way that the script add by it self the uvwmap modifier to a selection of objects, istanced or not?
also to chose which mapping way to add? like to randomize between cylindrical and spherycal?

Lobo Niebla

muchas gracias, despues de un rato de busqueda di con tu codigo y la verdad, mis aplausos que gran trabajo.

Return to top