TotallyRadCAD.com: All things CAD & Totally Rad by Michael Donovan

TIP #: 2012.006 – RENAME


The “RENAME” command allows you to change the names of Blocks, Dimension Styles, Layers, Linetypes, Materials, Multileader Styles, Plot Styles, Table Styles, Text Styles, UCSs, Viewports and Views.

This command comes in real handy organizing objects in your drawing and changing the names of objects in old drawings to your latest standard naming convention.

Ok, Let’s get started Dude.

At the AutoCAD command prompt, Type “RENAME” and press "Enter". You will be presented the “Rename” Dialog Box.
  1. Select from the “Named Objects” list the object type to be renamed.

  2. Select from the “Items” list the item to be renamed. (The “Old Name:” box will then have the name of the item being renamed.)

  3. In the box below the “Old Name” type in the block name you would like to use and pick the “Rename To:” button.

  4. Repeat the previous steps until you are done renaming all the objects your heart desires.

  5. When you are done renaming all the objects you need to rename select “OK”.
TADA! But wait there’s more.

Let’s say you have a whole lotta object items to rename in a whole lotta DWG files.

When you type “-RENAME” the command works without the dialog box which in turn will give you the ability to write scripts or lisp files that you can then execute to rename a bunch of objects.

Here is the tricky part. If an object name in your script or lisp routine does not exist then you are going to get an error and the routine will not complete.

What I recommend is to create a lisp routine so you can use an “IF THEN ELSE” statement to check and make sure the object you want to change exists before you attempt to rename it.

OK. Here we go. I’m gonna try to keep it real simple Dude.

Open the Windows program “NOTEPAD”.

Add the following lines into your notepad. The following lines are just a sample and it will be up to you the change them to suit your needs. (I recommend highlighting the following and using copy paste then change the following to suit your need.)
      (if (tblsearch "block" "OldBlock-ABC" )
      (command "-RENAME" "B" "OldBlock-ABC" "NewBlock-123"))

      (if (tblsearch "block" "OldBlock-DEF" )
      (command "-RENAME" "B" "OldBlock-DEF" "NewBlock-456"))

      if (tblsearch "block" "OldLayer-GHI" )
      command "-RENAME" "B" "OldBlock-GHI" "NewBlock-789"))
Now we need to talk about what is happening.
  1. The first “IF” statement is checking to see if a “block” exists in the drawing named “OldBlock-ABC”.

  2. If that block does exist then it is going to run the following command to rename that block to “NewBlock-123” and then go to the next “IF” statement.

  3. If that block does not exist then it is going to skip the command and go to the next “IF” statement.
With that being said it is time for you to replace my block names with the ones you are using and add all necessary “IF” statements you need.

Also, You can change the word “block” to “layer” or other “Named Object” type to rename different object type values. Then change the “B” to “LA” for layer or use other “-RENAME” option to match the “Named Object” type previously specified.

Now save the file as “Rename Objects.lsp” to your desktop

Open a CAD file that contains “Named Objects” you would like to rename per the “Named Objects” and values you specified.

Drag and drop the file “RenameObjects.lsp” from your desktop and drop on top of your open drawing. If you see “Command: nil” the command completed successfully.

You can double check by using the “RENAME” command and browse through your “Rename” dialog box for the objects you attempted to change.

FYI Dude,
To run your “RenameObjects.lsp” routine in every drawing you open type “APPLOAD” and hit “Enter”.
  1. Select the “Contents” button under Startup Suite in the “Load/Unload Applications” dialog box.

  2. Pick “Add” in the “Startup Suite” dialog box.

  3. Find your “RenameObjects.lsp” routine, select it and pick “Open”.

  4. Pick “Close” in the “Startup Suite” dialog box.

  5. Pick “Close” in the “Load/Unload Applications” dialog box.

Seven-Six-Two Millimeter, Full Metal CAD!



Phone: (702) 772-2747 • Email: Michael@TotallyRadCAD.com