How To > Quickly Rename Selected Objects |
A very often required task in the daily 3ds Max practice is the mass-changing of object properties. Here is a very simple renaming script that shows how easy and powerful MAXScript can be when working with multiple objects. Using this example as a starting point, you could develop scripts that change other object properties with a single click...
The macroScript will be called RenameThem. To use the script, you can go to Customize... and drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or assign to a keyboard shortcut.
The macroScript will present the user with a dialog to enter a new base name. A dialog requires a rollout. We define a new rollout stored in the variable rename_rollout and titled "Enter New Base Name". The rollout will contain two UI elements.
The first UI element is a text box called base_name. It will have no default text when created.
The second UI element is a button called rename_them. It will display the text "RENAME SELECTED OBJECTS... ".
This is the button’s event handler. It will be executed each time the button is pressed.
When the button is pressed, we check the base name first. The edittext box has a property called .text which gives access to the currently entered text. If the text is not the empty string, we can go on with the renaming – this means the user has entered a meaningful base name.
The i loop will iterate through all selected objects. For each object, a new unique name will be generated using the base name entered in the edittext box. The resulting name will be assigned to the .name property of the current object.
When the script is executed, the createDialog function will take the rollout defined above and display it in a floating dialog with the width of 250 pixels and height of 50.
Evaluate the script. To use it, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut.
Start the script – the dialog will open in the center of the desktop. Select any number of objects to be renamed and enter a new base name. Press the button and check the names of the selected objects – they must have the same base name with unique sequential numbers now. You can repeat this as often as you want or close the dialog by pressing the X button of the dialog.
As already mentioned, you could modify the script to mass-change other object properties.