Jump to content

Rename Layer by Part of old layer name


acad1985

Recommended Posts

Hello Everyone.

I have a Lisp to rename the Layer by Part of Layer name. but the code is not working.

 

(defun C:Test()
(if (setq xlay (ssget "_X" '((8 . "*_Proposed_*"))))
(command "-layer" "r" xlay "Proposed Entity" "")
)
)

 

I want to select the layers which is having "Proposed" in their Name, then rename to PROPOSED ENTITY.

 

(Layer names like, Region_Proposed_Street, City_Proposed_street)

 

If someone can help me thank you very much.

Link to comment
Share on other sites

Hello Everyone.

I have a Lisp to rename the Layer by Part of Layer name. but the code is not working.

 

(defun C:Test()
(if (setq xlay (ssget "_X" '((8 . "*_Proposed_*"))))
(command "-layer" "r" xlay "Proposed Entity" "")
)
)

I want to select the layers which is having "Proposed" in their Name, then rename to PROPOSED ENTITY.

 

(Layer names like, Region_Proposed_Street, City_Proposed_street)

 

If someone can help me thank you very much.

 

Your code isn't working and won't work because: 1. You are trying to pass a selection set to the layer command. 2. The selection set will contain all entities on layers with "Proposed" in the layer name, NOT the layer itself. 3. Your code is attempting to give multiple layers the same name, unless your mean to substitute "Proposed Entity" for "Proposed" in the existing layer name? 1 & 2 are surmountable , but 3 isn't and needs a rethink e.g.

Link to comment
Share on other sites

Is there any other way to do this..?

Whatever the layers having Proposed in their name. That should be rename to Proposed Entity.

Can we done by using Layer merge.?

Link to comment
Share on other sites

Hi,

 

Just create that new layer name if its already existed then make a selection set of those objects on the old layers then move them to the new layer.

Link to comment
Share on other sites

Is there any other way to do this..?

Whatever the layers having Proposed in their name. That should be rename to Proposed Entity.

Can we done by using Layer merge.?

 

As per Tharwat's post this should accomplish what you want :

 

(defun c:move2layer ( / *error* c_doc c_lyrs cmde n_lyr ss ss_objs)
  (defun *error* ( msg )
     (if cmde (setvar 'cmdecho cmde))
     (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
     (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
     (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_lyrs (vla-get-layers c_doc)
        n_lyr "Proposed Entity"
  )
  (if (/= (getvar 'cmdecho) 0) (progn (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0)))
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (vla-startundomark c_doc)
  (if (not (tblsearch "layer" "Proposed Entity")) (vla-add c_lyrs n_lyr))
  (setq ss (ssget "_X" '((8 . "*_Proposed_*"))))
  (if ss (setq ss_objs (vla-get-activeselectionset c_doc)))
  (vlax-for obj ss_objs
     (vlax-put obj 'Layer n_lyr)
  )
  (setq ss nil
        ss_objs nil
  )
  (if cmde (setvar 'cmdecho cmde))
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
);end_defun

 

Type "move2layer" to run

 

It will move all objects on layers with "_Proposed_" in their name into a layer called "Proposed Entity".

 

If the layer doesn't exist it will create it.

Link to comment
Share on other sites

Hi Tharwat

Thanks for your reply..

Just create that new layer name if its already existed then make a selection set of those objects on the old layers then move them to the new layer.

 

Could you please tell me how to do this.?

Link to comment
Share on other sites

Hi Tharwat

Thanks for your reply..

Could you please tell me how to do this.?

Hi,

 

Be sure to have objects on unlocked layers in prior of invoking / running the following routine.

 

(defun c:Test ( / s i o e)
    (and (setq i -1 s (ssget "_X" '((8 . "*_Proposed_*"))))
         (while (setq o (ssname s (setq i (1+ i))))       
            (entmod (subst '(8 . "Proposed Entity") (assoc 8 (setq e (entget o))) e)))
      )  
 (princ)
 )

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