Randomizer - Overview

Platform: 3ds Max 2008+ (MAXScript)
Status: Released - V1.0
Address: www.GeoffSamuel.com/Scrip_Files.php?proj=6


The Randomizer is designed to quickly allow for the minor alteration in position, size and texture to multiple selected objects so to give each one a unique looking appearance.
This script is lightweight and easy enough to script custom parameters, perfect for background crowd based sequences where time is a factor. Easy to use by running the maxscript file, selecting the objects you want to vary, enter the parameters, and textures, and hit go! Simple as that!
It is worth noting, that the script expects, and only can work with, materials that are stored in a multi-sub object material.

Code

------------------------------------------------------
--                 Randomizer                  --
--         Created by Geoffrey Samuel          --
--        Email: Geoff@geoffsamuel.com        --
--       Website: www.geoffsamuel.com     --
--                (Version 1.0)                    --
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
/* LEGAL AND COPYRIGHT  INFO
------------------------------------------------------
Copyright (c) 2007-2010, Geoff Samuel
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

------------------------------------------------------
/* OTHER  INFO
------------------------------------------------------

It would be appreciate if the author could be informed to the use of the plugin/tool/code as to promote the usage of the plugin/tool/code.
Any modifications done to the plugin/tool/code for improved functionality or stability would be welcome as keep building off a single plugin/tool/code allowing for more people to benefit,
although this is not mandatory.

Bugs and feature requests to: Support@GeoffSamuel.com

------------------------------------------------------
/* BUILD AND VERSION INFO
------------------------------------------------------

Build date: 03/11/2010


Further features to be implemented: (build version 1.2)
* Implmented rotations

Version History: (build version 1.0)
* Project Started.

*/
--UI
rollout Randomizer "Randomizer" width:162 height:380
(
    --UI controls
    --SCALE
    groupBox grp1 "Scale" pos:[5,6] width:151 height:61 
    spinner Scale_Min "" pos:[48,20] width:97 height:16 range:[0,100000,1.2]
    spinner Scale_Max "" pos:[49,41] width:97 height:16 range:[0,1e+007,0.8]
    label lbl1 "Min" pos:[21,21] width:21 height:14
    label lbl2 "Max" pos:[21,42] width:21 height:14
    --POSITION
    groupBox grp2 "Position" pos:[5,76] width:151 height:214
    spinner Pos_X_Min "" pos:[47,104] width:97 height:16 range:[-1e+007,100000,-3] scale:0.1
    spinner Pos_X_Max "" pos:[48,125] width:97 height:16 range:[-1e+007,1e+007,5]
    label lbl3 "Min" pos:[20,105] width:21 height:14
    label lbl4 "Max" pos:[20,126] width:21 height:14
    groupBox grp3 "X Axis" pos:[13,88] width:138 height:61
    spinner Pos_Y_Min "" pos:[48,170] width:97 height:16 range:[-1e+007,100000,-3] scale:0.1
    spinner Pos_Y_Max "" pos:[49,191] width:97 height:16 range:[-1e+007,1e+007,5]
    label lbl5 "Min" pos:[21,171] width:21 height:14
    label lbl6 "Max" pos:[21,192] width:21 height:14
    groupBox grp4 "Y Axis" pos:[14,154] width:138 height:61
    spinner Pos_Z_Min "" pos:[48,238] width:97 height:16 range:[-1e+007,100000,-3] scale:0.1
    spinner Pos_Z_Max "" pos:[48,259] width:97 height:16 range:[-1e+007,1e+007,5]
    label lbl7 "Min" pos:[21,239] width:21 height:14
    label lbl8 "Max" pos:[21,260] width:21 height:14
    groupBox grp5 "Z Axis" pos:[14,222] width:138 height:61
    --MATERIAL
    materialButton choosemtl "Material to Random" pos:[8,311] width:147 height:25
    checkbox Use_Random_mat "Use Random Material" pos:[9,293] width:141 height:15
    --BUTTON
    button ControlButton "DO IT!" pos:[8,342] width:147 height:25
   
    --material button event
    on choosemtl picked mtl do(
        --WILL ONLY WORK IF THE MATERIAL IS MULTI-SUB OBJECT MATERIAL, OTHERWISE THROW ERROR AND REMOVE VALUE
        if(classof mtl != multimaterial)do(
            messagebox "Wrong type of material!\nMust be Multi-sub object level material" title:"Randomizer Error"
            choosemtl.material = undefined
        )
    )
   
    --ControlButton event
    on ControlButton pressed  do(
        --check that at least one object is slected
        if(selection.count == 0)then(
            messagebox "No Objects Selected" title:"Randomizer Error"
        )else(
            -- go through each selected object
            for i in selection do(
                --generate a random uniform scale and apply it
                local scal = random Scale_Max.value Scale_Min.value
                i.scale = [scal,scal,scal]
                --generate a random point 3 value based off the random UI values, and apply it
                local pos = point3 (random Pos_X_Min.value Pos_X_Max.value) (random Pos_Y_Min.value Pos_Y_Max.value) (random Pos_Z_Min.value Pos_Z_Max.value)
                i.pos += pos
                --check if the material part is being used, and a material is selected
                if((Use_Random_mat.checked == true) AND (choosemtl.material != undefined))do(
                    --get a random material from the materials in the multi-sub object level and apply it.
                    ran = random 1 choosemtl.material.numsubs
                    i.material = choosemtl.material[ran]
                )
            )
        )
    )
)
--create the UI
createdialog Randomizer

Script Download

The script can be downloaded here