How To - Practical Examples >

# How To ... Quickly Rename Selected Objects

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...

Related Topics:

Defining Macroscripts

NATURAL LANGUAGE
Package the code as macroScript to be used as button, menu or shortcut.
Define a rollout to create a dialog
Define an edit text box in the rollout to enter the new base name
Define a button to initiate the renaming
Define a pressed handler for the button
Check whether the entered name is valid
If yes, go through all selected objects and assign unique names using the base name string.
When started, create the dialog using the above definitions.

MAXSCRIPT
    macroScript RenameThem category: "HowTo"
    (
     rollout rename_rollout "Enter New Base Name"
     (
      edittext base_name ""
      button rename_them "RENAME SELECTED OBJECTS..."
      on rename_them pressed do
      (
       if base_name.text != "" do
        for i in selection do i.name = uniquename base_name.text
      )--end on
     )--end rollout
    createDialog rename_rollout 250 50
    )

## Step-By-Step:

    macroScript RenameThem category:"HowTo"
    (

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.

Defining Macro Scripts

    rollout rename_rollout "Enter New Base Name"
    (

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.

Rollout Clauses

    edittext base_name

The first UI element is a text box called base_name. It will have no default text when created.

Edittext

    button rename_them "RENAME SELECTED OBJECTS..."

The second UI element is a button called rename_them. It will display the text "RENAME SELECTED OBJECTS... ".

Button

    on rename_them pressed do
    (

This is the button’s event handler. It will be executed each time the button is pressed.

    if base_name.text != "" do
    for i in selection do i.name = uniquename base_name.text

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.

If Expression

For Loop

uniquename

    )--end on
    )--end rollout
    createDialog rename_rollout 250 50

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.

CreateDialog

    )

## Using the Script

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.

## Where to go from here

As already mentioned, you could modify the script to mass-change other object properties.

Back to

"How To" Tutorials Index Page