How to modify layer name with prefix ?

How to modify layer name with prefix ?

tencome
Contributor Contributor
1,615 Views
7 Replies
Message 1 of 8

How to modify layer name with prefix ?

tencome
Contributor
Contributor

I want to modify the layer name with lisp.Change to "AAA" at one time. 

 

 how to modify this command?    (command "rename" "layer" "BBB*" "AAA*" "")  .   

 

 

 

All layer with same prefix "BBB",    all need change to prefix "AAA".

Original Layer:   BBB_1,    BBB_22,    BBB_123 …………

After change:   AAA_1,    AAA_22,    AAA_123…………

 

 

0 Likes
Accepted solutions (1)
1,616 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@tencome wrote:

All layer with same prefix "BBB",    all need change to prefix "AAA".

Original Layer:   BBB_1,    BBB_22,    BBB_123 …………

After change:   AAA_1,    AAA_22,    AAA_123…………


 

command: Rename

pbejse_1-1649922913558.png

Click Rename To: then you're done

 

HTH

 

0 Likes
Message 3 of 8

tencome
Contributor
Contributor

I want to use lisp to automatic run this command, better not select in this window.

0 Likes
Message 4 of 8

pbejse
Mentor
Mentor

@tencome wrote:

I want to use lisp to automatic run this command, better not select in this window.


Why not?

 

Anway, would you want that to run with be multiple patterns? or just one particular name?

--> ("BBB_" "AAA_")("WALL_" "FLOOR_") 

 

Or you want the user to type-in the old and new prefix? which is incidentally the same as using the rename dialog

 

0 Likes
Message 5 of 8

tencome
Contributor
Contributor

No one particular name,    any layer with prefix "BBB"  need change to "AAA".

 

I don't want user to type-in new prefix,  just follow LISP commend  "AAA".

 

 

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor
Accepted solution

@tencome wrote:

No one particular name,    any layer with prefix "BBB"  need change to "AAA".

 


 

(defun c:BtoA (/ a oldname newname)			
  (while (setq a (tblnext "LAYER" (null a)))
    (and
      (wcmatch (setq oldname (cdr (assoc 2 a))) "BBB*")
      (not
	(tblsearch "LAYER"
		   (setq newname (vl-string-subst "AAA" "BBB" oldname))
	)
      )
      (vla-put-name
	(vlax-ename->vla-object (tblobjname "layer" oldname))
	newname
      )
    )
  )(princ)
)

 

0 Likes
Message 7 of 8

tencome
Contributor
Contributor

Thank you very much.

 

This seemed much more difficult than I thought.

0 Likes
Message 8 of 8

pbejse
Mentor
Mentor

@tencome wrote:

Thank you very much.

This seemed much more difficult than I thought.


Anytime @tencome , Glad it helps

 

Not that much difficult really, it is written in such a way we can modify it later to accept multiple patterns, using "command" invites a lot of issues depending on the AutoCAD version but that's just me 🙂

 

It would be more complex if we include an action if the new name already exists then we may need to merge the old with the new.

 

0 Likes