Rename Multiple Blocks

Rename Multiple Blocks

anderson51
Advocate Advocate
15,105 Views
36 Replies
Message 1 of 37

Rename Multiple Blocks

anderson51
Advocate
Advocate

Is there lisp routine that will allow you to rename multiple blocks at once?

 

 

Thanks,

Anderson51

0 Likes
Accepted solutions (1)
15,106 Views
36 Replies
Replies (36)
Message 21 of 37

dmfrazier
Advisor
Advisor

Assuming you want to change all names that begin with "DS-301-145..." to "DS-302-146..." (for example), select one of the names that has that common beginning string, so that its name appears in the upper name field. Now, edit the string to replace everything that follows the characters you want to change with an asterisk ("*"). Now all of the block names that match up to that character will be highlighted in the listing. Now enter what you want that string to read in the lower name field (again using the asterisk) and hit the button.

 

Of course, it's important to understand that this method works only with names that follow similar patterns. And sometimes the renaming has to be done in logical steps. Your example seemed to be that, so I thought you might benefit from learning about this time-saving technique.

 

Practice.

0 Likes
Message 22 of 37

Tom_Fitz
Contributor
Contributor

Someone in the past bound all the Xrefs together creating unnecessary prefixes to every block and layer.

 

The RENAME command brings up this dialog box: 

Note in the OLD NAME box the prefix I want to get rid of is entered.

The RENAME TO box shows the thing I want to name it to.

Tom_Fitz_0-1685886046240.png

 

Click the RENAME TO button and all block names are changed.

 

Tom_Fitz_1-1685886087088.png

 

No programming required.  It would be helpful if Autodesk made this feature more widely known.

 

 

Message 23 of 37

dmfrazier
Advisor
Advisor

"It would be helpful if Autodesk made this feature more widely known."

 

dmfrazier_0-1685966680589.png

 

0 Likes
Message 24 of 37

warren.clements
Explorer
Explorer

I'm having the same issue. I've exported several cad files from revit, and every block has "-_3D - [my name]_" at the end of the block name. I would like to retain each block's name but without my name on the end. I was able to use the wildcard * along with the text I would like to remove for the block names, but I can't figure out how to remove that portion of the names without going line by line which would take days.

 

0 Likes
Message 25 of 37

dmfrazier
Advisor
Advisor

Be sure to include a small portion of the block name that you want to remain after the asterisk, like so:

find: *-_3D - warren_clements_

replace: *-_3D

 

(Everything that ends with this, I want it to end with this.)

0 Likes
Message 26 of 37

warren.clements
Explorer
Explorer

I keep trying that exact text, and it runs through the names like its going to replace/remove the text but it doesn't. Thanks for the quick response.

0 Likes
Message 27 of 37

dmfrazier
Advisor
Advisor

Please post a screenshot of the Rename dialog with your entries in each field.

0 Likes
Message 28 of 37

warren.clements
Explorer
Explorer

See attached. It will select all of the matching text as if it plans to replace.

0 Likes
Message 29 of 37

dmfrazier
Advisor
Advisor

If all of the block names that match the criteria do not become highlighted in the list, then there must be something different in the criteria you've entered.

 

Try starting smaller and then building up... and hopefully you'll see where the difference is.

0 Likes
Message 30 of 37

warren.clements
Explorer
Explorer

That's what I was trying to say. It will select all of the text, and when I click rename all of the text is re-selected.

0 Likes
Message 31 of 37

dmfrazier
Advisor
Advisor

I understand now.

It appears I've been wrong about how this works, because I just tried something similar in one of my DWGs and it does the same thing you report. I could've sworn I've done this before (but apparently not).

I apologize for misleading you.

 

I think your only other option may be to use strings of ????... of various lengths as stand-ins for the segments you want to retain in blocknames with similar lengths and suffixes. (This doesn't seem like it will be much of a time-saver, though.)

0 Likes
Message 32 of 37

JMARTINEZP5F4F
Participant
Participant

how does it reference a "Block A"?  I get an error saying "Cannot find Block A"

0 Likes
Message 33 of 37

CodeDing
Advisor
Advisor

@JMARTINEZP5F4F ,

 

If you're referencing my code in message 2, then you're probably implementing it wrong. 

If you do not have a block in your drawing called "Block A" then you should remove that line from the code.

Could probably be written better like:

(defun c:RMB ( / lstBlocks cnt)
  ;; Rename Multiple Blocks
  ;; Prep
  (setq lstBlocks '(
    ;("old_name" "new_name")
    ("Block A" "Block 1")
    ("BLOCK B" "Block 2")
  ))
  ;; Begin work
  (setq cnt 0)
  (setvar 'CMDECHO 0)
  (foreach blk lstBlocks
    (if (tblsearch "BLOCK" (car blk))
      (progn
        (command "-RENAME" "b" (car blk) (cadr blk))
        (setq cnt (1+ cnt))
      );progn
    ;else
      (prompt (strcat "\nBlock \"" (car blk) "\" not in drawing."))
    );if
  );foreach
  (setvar 'CMDECHO 1)
  ;; Finish up
  (prompt (strcat "\nBlock Re-Naming Complete. " (itoa cnt) " blocks renamed."))
  (princ)
);defun

 

Best,

~DD

0 Likes
Message 34 of 37

vladimir_michl
Advisor
Advisor

You can also mass-rename such blocks with the RRename utility - see

https://www.cadforum.cz/en/rename-on-steroids-complex-renaming-of-autocad-objects-tip9265

 

the search/replace pair will be something like:

DS-(\\d.+)-(\\d.+)-a(\\d.+)

DS-{$1+1}-$2-a$3

then - similarly:

{$1+1}

then

a{$1+7}

 

Vladimir Michl, www.arkance.worldwww.cadforum.cz

 

0 Likes
Message 35 of 37

JTBWorld
Advisor
Advisor

Are we now again allowed by Autodesk to promote our own apps? 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 36 of 37

vladimir_michl
Advisor
Advisor

I am sorry if this is breaking any rules, it is non-commercial freeware. But still, perhaps blatant advertising. Can be freely deleted.

 

Vladimir Michl, www.arkance.world  -  www.cadforum.cz

 

Message 37 of 37

jreidKVSUZ
Advocate
Advocate

You can also use Excel to help you rename all the blocks you have since there are so many. This may seem like a lot to do but renaming here is faster than the RENAME inside AutoCAD.

 

Also, not sure if someone told you but the reason you have the AP-1$0$ is because someone did a XREF BIND BIND vs XREF BIND INSERT.  If you have all the Native Files, Redo your XREF BIND INSERT. You can open a drawing, type XREF and select 100 or more files, if you need to. Let them XREF in at 0,0. The go to XREF, select them all and BIND INSERT. Done. No more AP-1$0$.

 

Start by DATAEXTRATION. Create a new Excel file and choose only Blocks.

  1. When you open the Excel file remove all columns except your block names.
  2. Remove the top Row. You don’t need that. Now only thing inside is Column A with your Old Block Names.
  3. Select everything by hitting the top left square with the Arrow showing. Above Row 1 and before Column A.
  4. Now right click on that square and select Format Cells and change all Cells to TEXT. Then pick Ok.
  5. Add a New Column A. Inside type -RENAME.  Copy that all the way down for all your blocks.
  6. Now your Old Block names should be in Column B.
  7. Now Right Click Column B and ADD A NEW COLUMN B.
  8. Under Column B put in B all the way down for all your blocks.
  9. Now your Old Block names should be in Column C.
  10. Now leave Column D empty.
  11. Now in Column E, type your new Block Names.
  12. Now Select everything & hit Copy. But only what is between Column A & E. Not Column F.
  13. Open Notepad.  Now hit Paste. Then SAVEAS, lets call it SCRIPT-1.scr   (must have SCR).
  14. Now Drag and Drop the SCR into the drawing with the Blocks.
  15. This now should have completed your renaming and now PURGE, and SAVE.

Tip for your renaming of this type of block names. Copy Your Existing into Column E.

Select that Column and do a REPLACE and put in FIND WHAT:  AP-1$0$  

Don’t put anything in REPLACE WHAT and hit OK. Now your renaming is completed.

Seems like a lot, but very easy and fun to watch. Your file should look like my Paste below.

This works for Layer Names as well. Just replace the B with LA. Because I am sure they are messed up as well.

Hope this helps!

JRR!

jreidKVSUZ_0-1738253561622.png

 

 

0 Likes