Layer rename assistance

Layer rename assistance

DC-MWA
Collaborator Collaborator
866 Views
11 Replies
Message 1 of 12

Layer rename assistance

DC-MWA
Collaborator
Collaborator

Hello,

I'm hoping this has been done and someone can lead me in the right direction. I hoping to select a layer, get the name of the layer, and rename the layer as follows:

 

(SetQ En (EntGet (Car
(EntSel "\nSelect Object on Layer to Rename: "))))
(SetQ El (Cdr (Assoc 8 En)))

 

So let's say El = "A-ELEC-POWR"

 

I would like to rename El to = "A-NEWW-ELEC-POWR"

 

So i would like to insert "NEWW-" after the "A-" in the layer name.

 

Again, I'm hoping someone has done something similar with wcmatch or something..

Thank you.

0 Likes
Accepted solutions (1)
867 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant

Would you want to give it the change each time, or are you looking for something like a command to add specifically "NEWW-" always after the second character of the name of the Layer of a selected object?  [You could have separate commands to different infixes.]

 

Also, suppose you select an object on a Layer that already has that added?  Should there be "protection" against renaming Layer "A-NEWW-ELEC-POWR" to become "A-NEWW-NEWW-ELEC-POWR"?

 

In simplest terms, this will do the former:

(command "_.rename" "_layer" (setq oldname (cdr (assoc 8 (entget (car (entsel)))))) (lisped oldname))

It brings up a text editor with the current Layer name already filled in, and you can add whatever you want wherever you want, take part away, replace the whole thing, or edit it in any other way you like, and when you hit Enter, the Layer name will be changed.

 

And this will do the latter:

(command "_.rename" "_layer"

  (setq oldname (cdr (assoc 8 (entget (car (entsel))))))

  (strcat (substr oldname 1 2) "NEWW-" (substr oldname 3))

)

Kent Cooper, AIA
0 Likes
Message 3 of 12

DC-MWA
Collaborator
Collaborator

Hello,

Thank you for the response.

Ultimately, i will most likely add kword options to add NEWW, EXST, FUTR, DEMO options

 

And yes, the "protection" seems like a great idea.

 

0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

@DC-MWA wrote:

.... i will most likely add kword options to add NEWW, EXST, FUTR, DEMO options

And yes, the "protection" seems like a great idea.


A quickie, minimally tested:

 

(defun C:LNIF ; = Layer Name InFix
  (/ infix esel layold)
  (initget "Neww Exst Futr Demo")
  (setq infix (getkword "\nLayer name infix [Neww/Exst/Futr/Demo]: "))
  (while (setq esel (entsel "\nObject on Layer to have Infix added: "))
    (setq layold (cdr (assoc 8 (entget (car esel)))))
    (if (/= (strcase (substr layold 3 4)) (strcase infix))
      (command "_.rename" "_layer" layold
        (strcat (substr layold 1 2) (strcase infix) "-" (substr layold 3))
      ); command
    ); if
  ); while
  (princ)
); defun

 

It could be enhanced to remember which infix you last chose and offer it as default on subsequent use, report on Layers it didn't rename because they already had the infix, check for any of those infixes in the current name rather than just the selected one, as well as all the usual stuff [*error* handler, Undo begin/end wrapping, etc.].

 

I put the options with only initial capitals because if you show them in all capitals, you would need to type all four letters of the one you want [though there would be the option to pick it in the prompt], whereas here you can type only the first letter.  It gets all-capitalized in application.

Kent Cooper, AIA
0 Likes
Message 5 of 12

DC-MWA
Collaborator
Collaborator
Heck yea!!!
0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@DC-MWA wrote:
Heck yea!!!

Sounds like it worked....  I edited the Message a few times, probably overlapping your reply, including fixing one thing in the code [about the already-infixed check], so make sure you use the latest.

Kent Cooper, AIA
0 Likes
Message 7 of 12

DC-MWA
Collaborator
Collaborator
I dont seem to have the infix check??
0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@DC-MWA wrote:
I dont seem to have the infix check??

It's this:

(if (/= (strcase (substr layold 3 4)) (strcase infix))

If the 3rd through 7th characters of the current Layer name are different from the chosen infix [not case-sensitive], it will rename the Layer by adding that.  If they're the same, it won't, so you don't double up on that infix.  But as currently written, if [for example] they are "EXST" and you chose "DEMO", it will add "DEMO-" into the Layer name, for a different kind of doubling up -- that's why I mentioned that it could be made to check for any of those infixes already present, not just the chosen one.  I suppose it could be made to check for those, and if present, replace that part with your chosen one, instead of bypassing the Layer of that chosen object.

Kent Cooper, AIA
0 Likes
Message 9 of 12

DC-MWA
Collaborator
Collaborator

Thank you very much Mr Cooper!!!  You have made my day a bit more efficient. 

0 Likes
Message 10 of 12

ronjonp
Mentor
Mentor

@DC-MWA Here's also another one that puts selected items on a newly created prefixed layer. A bit different than Kent's layer rename which will apply to all objects in the drawing.

 

(defun c:layerprefix (/ e el l f s tm)
  ;; RJP - 04.03.2018
  (or (setq f (getenv "RJP_LayerPrefix")) (setq f (getenv "username")))
  (if (and (setq f (cond ((/= "" (setq tm (getstring (strcat "\nEnter prefix [<" f ">]: ")))) tm)
			 (f)
		   )
	   )
	   (setq s (ssget ":L" (list (cons 8 (strcat "~" f "*")))))
      )
    (progn (setenv "RJP_LayerPrefix" f)
	   (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	     (setq l (cdr (assoc 8 (entget e))))
	     (setq el (entget (tblobjname "layer" l)))
	     (if (not (tblobjname "layer" (strcat f l)))
	       (entmakex (subst (cons 2 (strcat f l)) (assoc 2 el) el))
	     )
	     (entmod (subst (cons 8 (strcat f l)) (assoc 8 (entget e)) (entget e)))
	   )
    )
  )
  (princ)
)

 

 

0 Likes
Message 11 of 12

DC-MWA
Collaborator
Collaborator

Hello,

I apologize for the delay. This is very cool. Thank you

0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

Your choices add more as required.

 

 

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 1))
(setq ans(ah:butts but "V" '("Choose a new string"  "NEWW" "EXST" "FUTR" "DEMO"))) ; ans holds the button picked

 

 

  

SeaHaven_0-1646453384626.png

 

0 Likes