Jump to content

Recommended Posts

Posted (edited)

I wish there was a lisp to change the layer name, just change the name. and I found lee-mac's lisp but can't use it.

I want to change the old layer name to the new layer name, like the rename command. Thank you

 

(defun c:layren ( / enx obj old new )
    (setq old "Layer_to_be_Renamed"
          new "New_Layer_Name"
    )
    (if (and (setq obj (tblobjname "layer" old))
             (setq enx (entget obj))
        )
        (entmod (subst (cons 2 new) (assoc 2 enx) enx))
    )
    (princ)
)

 

Edited by CADTutor
  • CADTutor changed the title to Layer name change
Posted

That code works perfectly.

 

So, if you have a layer named "Layer_to_be_Renamed"

then the script will change the layer name to "New_Layer_Name".

 

The question is: what would you like the code to do exactly?

Do you want to type the old layer, then type the new layer?

 

Here's what you could do:  Command LAYREN1

;; type old layer name, then type new layer name
(defun c:layren1 ( / old new )
	(layren (setq old (getstring "\nOld layer name: "))  (setq new (getstring "\nNew layer name: ")))
	(princ)
)


(defun layren ( old new  / enx obj )
    (if
		(if (and (setq obj (tblobjname "layer" old))
				 (setq enx (entget obj))
			)
			(entmod (subst (cons 2 new) (assoc 2 enx) enx))
		)
		(progn
			(princ (strcat 
				"\nLayer \""
				old
				"\" got renamed to \""
				new
				"\""
			))
		)
    )
)

 

But again, what do you want the code to do?  How do you want it to work?

rename layer.png

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...