Lisp Routine to automatically, rename any block listed in list from old name to new one .

Lisp Routine to automatically, rename any block listed in list from old name to new one .

dharunkumar.am
Advocate Advocate
441 Views
5 Replies
Message 1 of 6

Lisp Routine to automatically, rename any block listed in list from old name to new one .

dharunkumar.am
Advocate
Advocate

I am new to lisp routines , Is there any way to get a Lisp Routine which can automatically, rename any block listed in list from old name to new one in a single command in. 

0 Likes
Accepted solutions (2)
442 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Something like this [very similar to another current topic]:

 

(defun C:BNU () ; = Block Name Update
  (foreach item '(("Old1" "New1") ("Old2" "New2") ("OldA" "NewA") ("OldB" "NewB"))
    (if
      (and
        (tblsearch "block" (car item)); block exists in the drawing
        (not (tblsearch "block" (cadr item))); not duplicating an existing name
      )
      (command "_.rename" "_block" (car item) (cadr item)); then
    )
  )
  (princ)
)

 

EDIT:  [I just fixed a little something, so if you pulled the code very soon after originally posted, and it didn't work, try it again with the revision.]

A question:  Would it be likely that any of the new Block names is already the name of a Block in the drawing?  If that's possible, should the routine notify the User of any Block name(s) it was unable to change?

Kent Cooper, AIA
Message 3 of 6

dharunkumar.am
Advocate
Advocate
Thanks for the reply , can you tell me how to run this lisp after loading into the drawing using Appload.
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Just type the command name BNU [always the part immediately following the (defun C:].  You can change that command name to anything you prefer [other than a command name that already exists].

Kent Cooper, AIA
Message 5 of 6

dharunkumar.am
Advocate
Advocate

It works perfectly . Thank you so much .

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

If its a I just want it to run when I load, add (C:BNU) as last line in the lisp. I do this for most of my code.

 

 

  (princ)
)
(C:BNU)