Jump to content

copy/rename layer


ajax30

Recommended Posts

There shouldn't have been anything wrong with the original version I posted. I only changed my method to avoid the use of VLISP, but both should work. What problem did you have with the first?

 

Dialog box appeared but it was not changing name of layer

but maybe problem exists between keyboard and chair, because i was using it yesterday and it worked

Link to comment
Share on other sites

Dialog box appeared but it was not changing name of layer

but maybe problem exists between keyboard and chair, because i was using it yesterday and it worked

 

Strange. If you come across the error again, I'd appreciate a bit of info. :)

Link to comment
Share on other sites

  • 3 years later...

Hi Alan! I came across these forum and saw this very helpful code of yours. I just want to ask if its possible to modify your code wherein only the selected layer will change name and not affecting the other layers? It just happens that when I test it, all the layers with the same name also changes. I would appreciate any feedback of yours. I'm still learning LISP commands and creating this kind of code will require me a lot of time and experience to create :-)

 

-Jeremiah

Link to comment
Share on other sites

@Lee: You know, in retrospect, I don't know why I fooled with changing it to VL just to change the name. Brain wasn't screwed on all the way that day and all I did as a revision was clean up the code.

 

I decided to update mine to exclude the unneeded use of VL and to give the option to edit the current layer - something I've been meaning to add any way.

 

(defun c:RenL (/ ent old new lay)
 ;; Rename Layer of Selected Object or current layer
 ;; Required Subroutines: AT:Getstring
 ;; Alan J. Thompson, 11.30.09 / 05.21.13
 (while (progn (setvar 'ERRNO 0)
               (initget 0 "Current")
               (setq ent (entsel "\nSelect object on layer to change name [Current]: "))
               (if (eq (getvar 'ERRNO) 7)
                 (princ "\nMissed, try again.")
               )
        )
 )

 (cond
   ((not ent))
   ((member
      (setq new
             (AT:Getstring
               "Specify new layer name:"
               (if (eq (type ent) 'STR)
                 (cdr (assoc 2
                             (setq lay (entget
                                         (tblobjname "LAYER" (setq old (getvar 'CLAYER)))
                                       )
                             )
                      )
                 )
                 (cdr
                   (assoc 2
                          (setq lay (entget (tblobjname
                                              "LAYER"
                                              (setq old (cdr (assoc 8 (entget (car ent)))))
                                            )
                                    )
                          )
                   )
                 )
               )
             )
      )
      (list "" nil old)
    )
   )
   ((tblsearch "LAYER" new) (alert (strcat "Layer: \"" new "\" already exists!")))
   ((not (snvalid new)) (alert (strcat "\"" new "\" is an invalid name!")))
   ((entmod (subst (cons 2 new) (assoc 2 lay) lay))
    (alert (strcat "Layer: " old " renamed to: " new))
   )
   ((alert (strcat "Layer: " old " could not be renamed to: " new)))
 )

 (princ)
)



(defun AT:GetString (#Title #Default / #FileName #FileOpen #DclID #NewString)
 ;; Getstring Dialog Box
 ;; #Title - Title of dialog box
 ;; #Default - Default string within edit box
 ;; Alan J. Thompson, 08.25.09
 (setq #FileName (vl-filename-mktemp "" "" ".dcl")
       #FileOpen (open #FileName "W")
 )
 (foreach x '("TempEditBox : dialog {"                      "key = \"Title\";"
              "label = \"\";"        "initial_focus = \"Edit\";"
              "spacer;"              ": row {"              ": column {"
              "alignment = centered;"                       "fixed_width = true;"
              ": text {"             "label = \"\";"        "}"
              "}"                    ": edit_box {"         "key = \"Edit\";"
              "allow_accept = true;" "edit_width = 40;"     "fixed_width = true;"
              "}"                    "}"                    "spacer;"
              ": row {"              "fixed_width = true;"  "alignment = centered;"
              ": ok_button {"        "width = 11;"          "}"
              ": cancel_button {"    "width = 11;"          "}"
              "}"                    "}//"
             )
   (write-line x #FileOpen)
 )
 (close #FileOpen)
 (setq #DclID (load_dialog #FileName))
 (new_dialog "TempEditBox" #DclID)
 (set_tile "Title" #Title)
 (set_tile "Edit" #Default)
 (action_tile "accept" "(setq #NewString (get_tile \"Edit\"))(done_dialog)")
 (action_tile "cancel" "(done_dialog)")
 (start_dialog)
 (unload_dialog #DclID)
 (vl-file-delete #FileName)
 #NewString
)

 

Hi Alan! I came across these forum and saw this very helpful code of yours. I just want to ask if its possible to modify your code wherein only the selected layer will change name and not affecting the other layers? It just happens that when I test it, all the layers with the same name also changes. I would appreciate any feedback of yours. I'm still learning LISP commands and creating this kind of code will require me a lot of time and experience to create :-)

 

-Jeremiah

Link to comment
Share on other sites

 

(defun c:RenL (/ ent old new lay)
 ;; Rename Layer of Selected Object or current layer
 ;; Required Subroutines: AT:Getstring
 ;; Alan J. Thompson, 11.30.09 / 05.21.13
 (while (progn (setvar 'ERRNO 0)
               (initget 0 "Current")
               (setq ent (entsel "\nSelect object on layer to change name [Current]: "))
               (if (eq (getvar 'ERRNO) 7)
                 (princ "\nMissed, try again.")
               )
        )
 )

 (cond
   ((not ent))
   ((member
      (setq new
             (AT:Getstring
               "Specify new layer name:"
               (if (eq (type ent) 'STR)
                 (cdr (assoc 2
                             (setq lay (entget
                                         (tblobjname "LAYER" (setq old (getvar 'CLAYER)))
                                       )
                             )
                      )
                 )
                 (cdr
                   (assoc 2
                          (setq lay (entget (tblobjname
                                              "LAYER"
                                              (setq old (cdr (assoc 8 (entget (car ent)))))
                                            )
                                    )
                          )
                   )
                 )
               )
             )
      )
      (list "" nil old)
    )
   )
   ((tblsearch "LAYER" new) (alert (strcat "Layer: \"" new "\" already exists!")))
   ((not (snvalid new)) (alert (strcat "\"" new "\" is an invalid name!")))
   ((entmod (subst (cons 2 new) (assoc 2 lay) lay))
    (alert (strcat "Layer: " old " renamed to: " new))
   )
   ((alert (strcat "Layer: " old " could not be renamed to: " new)))
 )

 (princ)
)



(defun AT:GetString (#Title #Default / #FileName #FileOpen #DclID #NewString)
 ;; Getstring Dialog Box
 ;; #Title - Title of dialog box
 ;; #Default - Default string within edit box
 ;; Alan J. Thompson, 08.25.09
 (setq #FileName (vl-filename-mktemp "" "" ".dcl")
       #FileOpen (open #FileName "W")
 )
 (foreach x '("TempEditBox : dialog {"                      "key = \"Title\";"
              "label = \"\";"        "initial_focus = \"Edit\";"
              "spacer;"              ": row {"              ": column {"
              "alignment = centered;"                       "fixed_width = true;"
              ": text {"             "label = \"\";"        "}"
              "}"                    ": edit_box {"         "key = \"Edit\";"
              "allow_accept = true;" "edit_width = 40;"     "fixed_width = true;"
              "}"                    "}"                    "spacer;"
              ": row {"              "fixed_width = true;"  "alignment = centered;"
              ": ok_button {"        "width = 11;"          "}"
              ": cancel_button {"    "width = 11;"          "}"
              "}"                    "}//"
             )
   (write-line x #FileOpen)
 )
 (close #FileOpen)
 (setq #DclID (load_dialog #FileName))
 (new_dialog "TempEditBox" #DclID)
 (set_tile "Title" #Title)
 (set_tile "Edit" #Default)
 (action_tile "accept" "(setq #NewString (get_tile \"Edit\"))(done_dialog)")
 (action_tile "cancel" "(done_dialog)")
 (start_dialog)
 (unload_dialog #DclID)
 (vl-file-delete #FileName)
 #NewString
)

 

Hi Alan! I came across these forum and saw this very helpful code of yours. I just want to ask if its possible to modify your code wherein only the selected layer will change name and not affecting the other layers? It just happens that when I test it, all the layers with the same name also changes. I would appreciate any feedback of yours. I'm still learning LISP commands and creating this kind of code will require me a lot of time and experience to create :-)

 

-Jeremiah

Link to comment
Share on other sites

Hi Alan! I came across these forum and saw this very helpful code of yours. I just want to ask if its possible to modify your code wherein only the selected layer will change name and not affecting the other layers? It just happens that when I test it, all the layers with the same name also changes. I would appreciate any feedback of yours. I'm still learning LISP commands and creating this kind of code will require me a lot of time and experience to create :-)

 

-Jeremiah

 

I'm not sure I understand your predicament.

You cannot have more than one layer in a drawing with the same name, so the command RENL functions as it should.

 

Are you trying to change the layer of just one selected object? If so, I suggest you look at CopyToLayer.

Link to comment
Share on other sites

I'm not sure I understand your predicament.

You cannot have more than one layer in a drawing with the same name, so the command RENL functions as it should.

 

Are you trying to change the layer of just one selected object? If so, I suggest you look at CopyToLayer.

 

 

Hi Alan! Thanks for your reply. What I'm trying to do is to rename the layer of a selected polyline and rename it (e.g. by putting a suffix on it) so that we can separate its name for objects with the same layer. I am trying to do a data extract of each polyline but the problem is that they have the same layer and doing data extract cannot identify it as a unique entity. Our easy approach is to change the layer's name individually by putting a suffix on it. (e.g. Layer name E-PLAN-TRCH-DC --> should become E-PLAN-TRCH-DC-01, E-PLAN-TRCH-DC-02, E-PLAN-TRCH-DC-03, etc.)

 

I would appreciate any feedback from yours :-)

 

Regards,

Jeremiah

Link to comment
Share on other sites

Hi Alan! Thanks for your reply. What I'm trying to do is to rename the layer of a selected polyline and rename it (e.g. by putting a suffix on it) so that we can separate its name for objects with the same layer. I am trying to do a data extract of each polyline but the problem is that they have the same layer and doing data extract cannot identify it as a unique entity. Our easy approach is to change the layer's name individually by putting a suffix on it. (e.g. Layer name E-PLAN-TRCH-DC --> should become E-PLAN-TRCH-DC-01, E-PLAN-TRCH-DC-02, E-PLAN-TRCH-DC-03, etc.)

 

I would appreciate any feedback from yours :-)

 

Regards,

Jeremiah

 

Quick and dirty example of incriminating the layer name to then create...

 

(defun _layerCopyInc (layerName / _layInc i)

 (defun _layInc (n i / nn)
   (if (tblsearch "LAYER"
                  (setq nn (strcat n
                                   "-"
                                   (if (< i 10)
                                     (strcat "0" (itoa i))
                                     (itoa i)
                                   )
                           )
                  )
       )
     (_layInc n (1+ i))
     nn
   )
 )

 (if (wcmatch layerName "*-##")
   (setq i         (atoi (substr layerName (- (strlen layerName) 1)))
         layerName (substr layerName 1 (- (strlen layerName) 3))
   )
   (setq i 1)
 )

 (_layInc layerName i)
)

Link to comment
Share on other sites

Quick and dirty example of incriminating the layer name to then create...

 

(defun _layerCopyInc (layerName / _layInc i)

 (defun _layInc (n i / nn)
   (if (tblsearch "LAYER"
                  (setq nn (strcat n
                                   "-"
                                   (if (< i 10)
                                     (strcat "0" (itoa i))
                                     (itoa i)
                                   )
                           )
                  )
       )
     (_layInc n (1+ i))
     nn
   )
 )

 (if (wcmatch layerName "*-##")
   (setq i         (atoi (substr layerName (- (strlen layerName) 1)))
         layerName (substr layerName 1 (- (strlen layerName) 3))
   )
   (setq i 1)
 )

 (_layInc layerName i)
)

 

Hi Alan, thanks for the big help! I just tried your code but I encountered some errors when I type the command _layerCopyInc. It doesn't show up in the command line. So I decided to change the command to c:layerCopyInc and remove the _ on the _layInc but it still gave me errors.

 

You just helped me a lot and I think its just a minor tweak on the code and this will run smooth.

 

Thanks!

Link to comment
Share on other sites

Hi Alan, thanks for the big help! I just tried your code but I encountered some errors when I type the command _layerCopyInc. It doesn't show up in the command line. So I decided to change the command to c:layerCopyInc and remove the _ on the _layInc but it still gave me errors.

 

You just helped me a lot and I think its just a minor tweak on the code and this will run smooth.

 

Thanks!

 

This is just a subroutine to be run within a larger routine. This will take the name and add/increment the suffix.

eg.

(_layerCopyInc "pizza") => "pizza-01"

(_layerCopyInc "pizza-01") => "pizza-02"

 

The rest of the code is:

select object;

get layer name;

increment to get new layer name (using _layerCopyInc);

create new layer;

put selected object on new layer

Link to comment
Share on other sites

Many thanks Alan for the big help! I'll give it a shot to do the remaining code and embed the subroutine inside.

 

You really helped me a lot.

 

Regards,

Jeremiah

Link to comment
Share on other sites

Many thanks Alan for the big help! I'll give it a shot to do the remaining code and embed the subroutine inside.

 

You really helped me a lot.

 

Regards,

Jeremiah

 

You're welcome. Let me know if you need any help.

Link to comment
Share on other sites

  • 7 years later...
On 11/24/2016 at 8:03 AM, MasterApprentice said:

 

Hi Alan! I came across these forum and saw this very helpful code of yours. I just want to ask if its possible to modify your code wherein only the selected layer will change name and not affecting the other layers? It just happens that when I test it, all the layers with the same name also changes. I would appreciate any feedback of yours. I'm still learning LISP commands and creating this kind of code will require me a lot of time and experience to create 🙂

 

-Jeremiah

Hi
First of all, thank you for your lisp, it’s great.
Do you think it is possible to have the choice of either renaming the layer, or duplicating this layer with the same base name??

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