Monday, February 16, 2009

Create you own Rename Tools with MAXScript

Are you tired of renaming object in your scene? Based on Maxscript reference > How To ... Quickly Rename Selected Objects, I've created here a little tutorial that help novice user to create a personalized rename tool.

The Interface
  1. First of everything we will create an interface for our rename tool using Menu > MAXScript > Visual MAXScript Editor.
  2. Complete the interface as shown below, remember each elements in the interface must have unique name so that we can assigned each of them with their own controller/action and prevent them from conflicting each others.
  3. When you're done, save it as Interface.vms as a backup, in case we need to edit the interface we still have the option.
  4. Afterwards, save as (don't forget the extension is now .ms)
  • We will be using on entered event on the editBox (i.e. pressing Enter will excute the rename). Since clicking mouse button outside the editBox will triggered the on entered event, so to prevent the rename to be excuted twice, we will first set this button as enabled:false.
  • editBox default to leave blank. If you want to have a preset message, simply key in something for yourself.
  • Height of editBox must be lower than 18pixel to enable on entered event. So here we give it a height of 16px.

The Maxscript
  1. Go to Menu > MAXScript > Maxscript Editor and open your saved You will see the same maxscript as below. We will be adding our own maxscript to complete this tool.
  2. Let's complete the script as below:
rollout quickRename "Quick Rename" width:250 height:120
editText txt_name "" pos:[24,56] width:200 height:16
button btn_rename "RENAME!" pos:[48,80] width:75 height:25 enabled:false
button btn_cancel "CANCEL" pos:[136,80] width:75 height:25
button btn_head "Head" pos:[8,16] width:75 height:25
button btn_body "Body" pos:[88,16] width:75 height:25
button btn_leg "Leg" pos:[168,16] width:75 height:25

fn renameIt objName = ( -- function "rename"
global objName
for i in selection do = uniquename objName
)-- end

on btn_head pressed do renameIt "Head_"
on btn_body pressed do renameIt "Body_"
on btn_leg pressed do renameIt "Leg_"
on txt_name entered txt do (renameIt (txt + "_"; btn_rename.enabled=true)
on btn_cancel pressed do destroyDialog quickRename


createDialog quickRename
setFocus quickRename.txt_name

fn renameIt objName = ( -- function "rename"
for i in selection do = uniquename objName
)-- end

  • define a function renameIt() with variable objName
  • for...i enable rename to be excuted onto every selected objects. uniquename is used to assigned unique suffix on every object e.g. Head_01, Head_02, etc.

on btn_head pressed do renameIt "Head_"
Excute renameIt() and assigned string "Head_" into objName variable when btn_head is pressed.

on txt_name entered txt do (renameIt (txt + "_"; btn_rename.enabled=true)
Press "Enter" upon completion of name in txt_name will excute renameIt(). In the mean time also activate btn_rename

on btn_cancel pressed do destroyDialog quickRename
When btn_cancel is pressed, close the rename tool.

createDialog quickRename
Create a floating dialog to hold our rename tool, to be same name as "rollout".

setFocus quickRename.txt_name
Focus on the editBox(txt_name) when the dialog being created and opened.


In this section we will convert our script into macroscript, which will be loaded into Customize User Interface (CUI) , so that we can put it onto Toolbar or assigned Shortcut Key.
macroScript QuickRename category:"Tutorial" tooltip:"Quick Rename" Icon:#("AtmosApp",1)
-- "rollout" is to be put in here

  • QuickRename = name of macroscript
  • category = which category our tool is belong to under CUI
  • tooltip = name that appear when mouse over, also the name in CUI
  • Icon = see section below.

Creating Icon

We can make our own icon as well by adding the tag below onto the same line as our macroscript():

  • AtmosApp = icon file name (.bmp as standard), file to be placed in"3dsmax root\ui\Icons"
  • In this tutorial, we used "ui\Icons\AtmosApp*.bmp" as sample.
  • For more information, please read the maxscript reference.

Run Script...
  1. We're almost done here, now go to "MAXScript > Run Script..." and run your Afterward, go to "Customize User Interface > Toolbar > Category > Tutorial" and you will spot our lovely tool。
  2. Drag it onto your toolbar (if you don't have one, it's time for you do make your own one) and Voila! You can also assigned a shortcut key to it if you love to do so.
When you run the script, it will automatically create a ".mcr" into your 3dsmax "usermacro" folder, which located at "DRIVE:\Documents and Settings\Username\Local Settings\Application Data\Autodesk\3dsmax\2009 - 32bit\enu\UI\usermacros".

That mean if you do not like to run it as maxscript, you can actually save the script as .mcr, and put it under the mentioned folder, then restart your 3dsmax.

Technique apply here could be further more developed into assigning renderer preset, controlling material so on and so forth. So I hope you enjoy this tutorial. Feel free to let me know what you think about this tutorial, and thing that I can improve here.

Lastly, here is my version, Cheer~