Jump to content

Rename multiple blocks


vesper

Recommended Posts

Hi,

 

is there some lisp/script, which renames multiple blocks in multiple drawings. I have about 300 blocks and 300 drawings and i need to rename every block in every drawing (about 10 blocks in one drawing). All the same, there aren't every 300 blocks in every drawing and that causes problems. I have a script, which works if there is every 300 block in one drawing, but there never is all the blocks in one drawing.

 

Does anyone have an aid to deal with this problem?

Link to comment
Share on other sites

Do you wish to add a prefix (i.e. you have block names A1 to Z99 for example and you want to rename them to newA1 to newZ99) and/or a suffix (i.e. you have block names A1 to Z99 for example and you want to rename them to A1new to Z99new)to the name of the blocks; or do you wish to completely change their name (i.e. you have blocks names A1 to Z99 for example and you want to rename them to ZA1 to ZZ99)?

 

Also, is it every single block in your drawings you want to rename, or is it only a certain number of them ?

Link to comment
Share on other sites

I want to completely change their name (for example from "block1" to "square") and that should do to every single block in one drawing. There is about 10-20 blocks in one drawing, but in all drawings overall about 300 blocks. Every drawing has different kind of mix of blocks.

Link to comment
Share on other sites

I'd use something like this:

(defun c:renameb (/ btable badt)
 (setq btable '(("OLDNAME" . "NEWNAME")
                ("LEG6"    . "LEG4")))

 (foreach b btable
   (cond ((and (not (tblsearch "BLOCK" (cdr b)))
               (tblsearch "BLOCK" (car b)))
          (command "_.RENAME" "_Block" (car b) (cdr b)))
         ((tblsearch "BLOCK" (cdr b))
          (setq badt (cons b badt)))))

 (and badt
     (prin1 badt)
     (alert "Unable To Rename All BLOCKs"))

 (prin1))
 

-David

Link to comment
Share on other sites

Hi,

 

is there some lisp/script, which renames multiple blocks in multiple drawings. I have about 300 blocks and 300 drawings and i need to rename every block in every drawing (about 10 blocks in one drawing). All the same, there aren't every 300 blocks in every drawing and that causes problems. I have a script, which works if there is every 300 block in one drawing, but there never is all the blocks in one drawing.

 

Does anyone have an aid to deal with this problem?

 

I didn´t pay to much attention to your problem... but yesterday I found a similar block renamer... here is for your testing... If you type the old and new names inside the lisp... it will search for those names and replace them for the new names, and as far as I read yesterday. if old names don´t exist in the drawing.. it will go ahead on next until it's done.

 

It was made for layers originally, so I kind of modified it to make it work for blocks... I just tested it on a drawing and works as required... but it must have some unnecesary lines that I couldn´t understand (cause I am not a Programmer), but as far as I could see, It works for renaming blocks too. It may help you with your task.

 

Someone can take a look and fix unnecesary lines.

 

Also, after testing it on one drawing you can use it on a set of drawing using the batch.lsp and a starting script that loads this lisp on every drawing inside a directory... you can have your task done automatically..

 

 
;;function to rename a block.
;;if old block exists, and new block doesn't exist, the old block is simply renamed.
;;if old block exists, it does nothing
;;if old block it alerts 'Block not found'.
(defun renblock (ol nl / ss i ent )
 (cond ((and (tblsearch "block" ol) (not (tblsearch "block" nl))) 
 (command "._rename" "block" ol nl)
)
((and (tblsearch "block" ol)(tblsearch "block" nl))
  (setq ss (ssget "x" (list (cons 2 ol))))
  (setq i -1)
   (repeat (sslength ss)
      (setq ent (entget (ssname ss (setq i (1+ i))))
     ent (subst (cons 2 nl) (cons 2 (cdr (assoc 2 ent))) ent)
      )    
      (entmod ent)
          )
)
((not (tblsearch "block" ol))
  (prompt (strcat "\nBlock " ol " not found. "))
       )
 )
 (princ)
)
;;example
(defun c:test ()
 (renblock "old block1" "Renamed1")
 (renblock "old block2" "Renamed2")
 (renblock "old block3" "Renamed3")
)

 

to run a script in startup

http://www.cadtutor.net/forum/showthread.php?t=40551

Link to comment
Share on other sites

  • 3 years later...
David Bethel said:
I'd use something like this:

(defun c:renameb (/ btable badt)
 (setq btable '(("OLDNAME" . "NEWNAME")
                ("LEG6"    . "LEG4")))

 (foreach b btable
   (cond ((and (not (tblsearch "BLOCK" (cdr b)))
               (tblsearch "BLOCK" (car b)))
          (command "_.RENAME" "_Block" (car b) (cdr b)))
         ((tblsearch "BLOCK" (cdr b))
          (setq badt (cons b badt)))))

 (and badt
     (prin1 badt)
     (alert "Unable To Rename All BLOCKs"))

 (prin1))
 

-David

 

This worked excellently. I had 240 blocks that were for aluminum, and I needed the same shapes but for Galvanized, HotDipped Galv, and SS.

I pasted them into the table in that code. Ran it, Replace to change the material letters, ran it, repeat. Worked perfectly, saved me soooo much time. Thank you very much!

Link to comment
Share on other sites

  • 4 weeks later...

Hi there! Does anybody have the original lisp to -rename layers with use of wildcards in names, that Gilsoto13 modified to renaming blocks? I hope it could recognize wildcards to change layers too. Regular command line -rename unfortunately does not recognize wildcards...

 

 

Best regards,

mikitari

 

I didn´t pay to much attention to your problem... but yesterday I found a similar block renamer... here is for your testing... If you type the old and new names inside the lisp... it will search for those names and replace them for the new names, and as far as I read yesterday. if old names don´t exist in the drawing.. it will go ahead on next until it's done.

 

It was made for layers originally, so I kind of modified it to make it work for blocks... I just tested it on a drawing and works as required... but it must have some unnecesary lines that I couldn´t understand (cause I am not a Programmer), but as far as I could see, It works for renaming blocks too. It may help you with your task.

 

Someone can take a look and fix unnecesary lines.

 

Also, after testing it on one drawing you can use it on a set of drawing using the batch.lsp and a starting script that loads this lisp on every drawing inside a directory... you can have your task done automatically..

 

 
;;function to rename a block.
;;if old block exists, and new block doesn't exist, the old block is simply renamed.
;;if old block exists, it does nothing
;;if old block it alerts 'Block not found'.
(defun renblock (ol nl / ss i ent )
 (cond ((and (tblsearch "block" ol) (not (tblsearch "block" nl))) 
 (command "._rename" "block" ol nl)
)
((and (tblsearch "block" ol)(tblsearch "block" nl))
  (setq ss (ssget "x" (list (cons 2 ol))))
  (setq i -1)
   (repeat (sslength ss)
      (setq ent (entget (ssname ss (setq i (1+ i))))
     ent (subst (cons 2 nl) (cons 2 (cdr (assoc 2 ent))) ent)
      )    
      (entmod ent)
          )
)
((not (tblsearch "block" ol))
  (prompt (strcat "\nBlock " ol " not found. "))
       )
 )
 (princ)
)
;;example
(defun c:test ()
 (renblock "old block1" "Renamed1")
 (renblock "old block2" "Renamed2")
 (renblock "old block3" "Renamed3")
)

 

to run a script in startup

http://www.cadtutor.net/forum/showthread.php?t=40551

  • Thanks 1
Link to comment
Share on other sites

On request, this layer renaming routine will not work with wildcards either... but at least works fine.

 

 

;;function to rename a layer.
;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
;;if old layer doesn't exist, it does nothing.
(defun renlay (ol nl / ss i ent )
 (cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl))) 
 (command "._rename" "la" ol nl)
)
((and (tblsearch "layer" ol)(tblsearch "layer" nl))
  (setq ss (ssget "x" (list (cons 8 ol))))
  (setq i -1)
   (repeat (sslength ss)
      (setq ent (entget (ssname ss (setq i (1+ i))))
     ent (subst (cons 8 nl) (cons 8 (cdr (assoc 8 ent))) ent)
      )    
      (entmod ent)
          )
)
((not (tblsearch "layer" ol))
  (prompt (strcat "\nLayer " ol " not found. "))
       )
 )
 (princ)
)
;;example
(defun c:test ()
 (renlay "ARSTAIR" "A-Flor-Strs")
 (renlay "ARPARTITION" "A-Flor-Tptn")
 (renlay "ARWOOD" "A-Flor-Wdwk")
 (renlay "ARFURNITURE" "A-Furn")
 (renlay "ARWINDOW" "A-Glaz")
)

Link to comment
Share on other sites

Not working with wildcards will not help either :( But thanks Gilsoto13, I will keep it for future. So, anybody knows another lisp that could do the –rename on layers with wildcards? Maybe this question should be moved to a new thread already.

Best regards,

Link to comment
Share on other sites

Renaming anything with wild cards could be very troublesome. What would you do when have multiple scenarios that both answers would be viable NAMES. -David

Link to comment
Share on other sites

Maybe you can use some of these options to do what you need, You can remove a part of layer names by using any Bound Layer renaming routine available in the web, or combine it with a adding a suffix or prefix to layer names routine, both available in some threads and free files on the web.

 

It's a workaround, but maybe the only way to do what you need.... I have never seen a wildcard layer nor block renaming routine in the web in my life.

 

attached both of these routines in casi you may want to try them.

Not working with wildcards will not help either :( But thanks Gilsoto13, I will keep it for future. So, anybody knows another lisp that could do the –rename on layers with wildcards? Maybe this question should be moved to a new thread already.

 

Best regards,

Renamelyr_takes off bound xref names from layer names.lsp

add or delete layers suffix or preffix DLP DLS ALP ALS.lsp

Add prefix or sufix to layer names PSrename.zip

Link to comment
Share on other sites

Hi! Thank you very much. I will try them too.

By now I have used the renlay lisp of yours. I made manually a lists of names to convert and it did the job (no wildcards). Lucky me, I had only 4 sets of levels with some 20 layer on each level to rename. It could be worse if we had a skyscraper to do ;)

 

In renlay.lsp I have tweaked the “_.rename” to “-rename” just to force the command line behavior (the rename window was triggered sometimes when I ran it from the script).

 

I am not a lisp writer unfortunately; actually I can not imagine what wrong could happen if “–rename” would let wildcards as same as itst sister “_.rename” does. For we can efficiently write names with wildcards inside _.rename window, no problem.

 

Thank you for the help!

Best regards,

Link to comment
Share on other sites

  • 2 years later...

We will need a little more info than that.

 

Did you modify the name list ?

 

If so, what are BLOCK names ?

 

What version of ACAD ?

Link to comment
Share on other sites

  • 5 years later...

David can you plz explain in detail that how I replace the in LSP  the old block name and new block name?

Plz see the below that i edit

(defun c:renameb (/ btable badt)
 (setq btable '  (("OLDNAME" . "NEWNAME")
                 ("Field Mounted Discrete Instrument Style_block-2"    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-3    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-4    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-7    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-6    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-10    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-5    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-9    . "tag baloon")
                 ("Field Mounted Discrete Instrument Style_block-8    . "tag baloon")))
                

 (foreach b btable
   (cond ((and (not (tblsearch "BLOCK" (cdr b)))
               (tblsearch "BLOCK" (car b)))
          (command "_.RENAME" "_Block" (car b) (cdr b)))
         ((tblsearch "BLOCK" (cdr b))
          (setq badt (cons b badt)))))

 (and badt
     (prin1 badt)
     (alert "Unable To Rename All BLOCKs"))

 (prin1))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...