Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Make a layer name with increment numbering

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Make a layer name with increment numbering

    Hello everyone,

    I'm looking for a lisp that will create a new layer named LP-PLNT_TREE-SHT* (* = a number starting with 1 if the layer doesn't exist already and will advance in increments of 1 (2, 3, 4, etc. if I repeat the command) it also needs to be able to recognize the last number in the layer names for example if I open the drawing and it already has layers LP-PLNT_TREE-SHT1 and LP-PLNT_TREE-SHT2 and I type in the command, it will create a new layer called LP-PLNT_TREE-SHT3. I would like it to ask the user to select the layer color each time.

    If possible can it also have the viewpoint color set to green for all current viewpoints in the drawing as well as new viewports?

    Thanks so much,

  2. #2
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Hi,
    Try this, must be work's for a number of layer from 1 to 999

    Code:
    (defun c:inc_layer ( / lay lay_name flag lay_list last_lay col)
      (while (setq lay (tblnext "LAYER" (not flag)))
        (setq lay_name (strcase (cdr (assoc 2 lay))) flag T)
        (mapcar
          '(lambda (x)
            (if (wcmatch lay_name (strcat "LP-PLNT_TREE-SHT" x))
              (setq lay_list (cons lay_name lay_list))
            )
          )
          '("#" "##" "###")
        )
      )
      (if lay_list
        (setq last_lay (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list) '>)))
        (setq last_lay 0)
      )
      (prompt (strcat "Color for the layer LP-PLNT_TREE-SHT" (itoa last_lay)))
      (terpri)
      (while (not (setq col (acad_colordlg 7 nil))))
      (entmake
        (list
          (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2 (strcat "LP-PLNT_TREE-SHT" (itoa (1+ last_lay))))
          (cons 70 0)
          (cons 62 col)
          (cons 6 "Continuous")
          (cons 290 1)
          (cons 370 -3)
        )
      )
      (prin1)
    )

  3. #3
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Quote Originally Posted by Bruno.Valsecchi View Post
    Hi,
    Try this, must be work's for a number of layer from 1 to 999

    Code:
    (defun c:inc_layer ( / lay lay_name flag lay_list last_lay col)
      (while (setq lay (tblnext "LAYER" (not flag)))
        (setq lay_name (strcase (cdr (assoc 2 lay))) flag T)
        (mapcar
          '(lambda (x)
            (if (wcmatch lay_name (strcat "LP-PLNT_TREE-SHT" x))
              (setq lay_list (cons lay_name lay_list))
            )
          )
          '("#" "##" "###")
        )
      )
      (if lay_list
        (setq last_lay (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list) '>)))
        (setq last_lay 0)
      )
      (prompt (strcat "Color for the layer LP-PLNT_TREE-SHT" (itoa last_lay)))
      (terpri)
      (while (not (setq col (acad_colordlg 7 nil))))
      (entmake
        (list
          (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2 (strcat "LP-PLNT_TREE-SHT" (itoa (1+ last_lay))))
          (cons 70 0)
          (cons 62 col)
          (cons 6 "Continuous")
          (cons 290 1)
          (cons 370 -3)
        )
      )
      (prin1)
    )
    Bruno,

    Thank you so much for doing this for me.

    I do have two items

    1.) A comment, when I run the program on the command line it is showing "Color for the layer LP-PLNT_TREE-SHT2" I already have a layer named LP-PLNT_TREE-SHT2 and it's my last layer with the number, shouldn't it state "Color for the layer LP-PLNT_TREE-SHT3" because #3 is the next in line?
    2.) A request, I forgot to ask for the code to add a Description (COMMAND "-LAYER" "MAKE" "Description" "Plant and landscape material: Trees (Sht*)" "LP-PLNT_TREE-SHT*" "") but I'm not sure where in your code, a code like this and also have it would advance the number.

    Regards,

    Cadd4la

  4. #4
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Quote Originally Posted by cadd4la View Post
    Bruno,

    Thank you so much for doing this for me.

    I do have two items

    1.) A comment, when I run the program on the command line it is showing "Color for the layer LP-PLNT_TREE-SHT2" I already have a layer named LP-PLNT_TREE-SHT2 and it's my last layer with the number, shouldn't it state "Color for the layer LP-PLNT_TREE-SHT3" because #3 is the next in line?
    2.) A request, I forgot to ask for the code to add a Description (COMMAND "-LAYER" "MAKE" "Description" "Plant and landscape material: Trees (Sht*)" "LP-PLNT_TREE-SHT*" "") but I'm not sure where in your code, a code like this and also have it would advance the number.

    Regards,

    Cadd4la
    This should meet your requests
    Code:
    (vl-load-com)
    (defun c:inc_layer ( / AcDoc lay lay_name flag lay_list last_lay col layerObj)
      (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (while (setq lay (tblnext "LAYER" (not flag)))
        (setq lay_name (strcase (cdr (assoc 2 lay))) flag T)
        (mapcar
          '(lambda (x)
            (if (wcmatch lay_name (strcat "LP-PLNT_TREE-SHT" x))
              (setq lay_list (cons lay_name lay_list))
            )
          )
          '("#" "##" "###")
        )
      )
      (if lay_list
        (setq last_lay (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list) '>)))
        (setq last_lay 0)
      )
      (prompt (strcat "Color for the layer LP-PLNT_TREE-SHT" (itoa (1+ last_lay))))
      (terpri)
      (while (not (setq col (acad_colordlg 7 nil))))
      (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_TREE-SHT" (itoa (1+ last_lay)))))
      (vlax-put layerObj 'color col)
      (vla-put-Description layerObj "Plant and landscape material: Trees (Sht*)")
      (prin1)
    )

  5. #5
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Bruno,

    Thank you again so much for doing this for me.

    I do still have one item

    1.) I was hoping that the description would match the number of the layer and advance each time, so it would be "Plant and landscape material: Trees (Sht*) *= 1, 2, 3, etc."

    Regards,

    Cadd4la

  6. #6
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Sorry,
    Simply replace
    Code:
    (vla-put-Description layerObj "Plant and landscape material: Trees (Sht*)")
    by
    Code:
    (vla-put-Description layerObj (strcat "Plant and landscape material: Trees (Sht " (itoa (1+ last_lay)) ")"))

  7. #7
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Bruno,

    It works perfectly.

    Thanks again,

    Cadd4la

  8. #8
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Bruno,

    Sorry, but I found a problem with the code.

    I need to not only make new layers named LP-PLNT_TREE-SHT1, SHT2, etc. but sometimes LP-PLNT_SHRB-SHT1, SHT2, etc. as well. So I copied your code and updated the layer name for the SHRB layer but now if I have LP-PLNT_TREE-SHT1 and LP-PLNT_TREE-SHT2 in the drawing and then use the code to add the SHRB layer I don't get LP-PLNT_SHRB-SHT1, I get LP-PLNT_SHRB-SHT3. can you fix it so it always starts with 1 and only advances to the next number of the last used number in that set of layer names?

    I still need a way to add them separately but is there also a way to make a group of layer names using the same color but with different layer names and descriptions?

    Cadd4la

  9. #9
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    If I understood correctly! This:
    Code:
    (vl-load-com)
    (defun c:inc_layer ( / AcDoc lay lay_name flag lay_list1 lay_list2 last_lay1 last_lay2 what col layerObj)
      (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (while (setq lay (tblnext "LAYER" (not flag)))
        (setq lay_name (strcase (cdr (assoc 2 lay))) flag T)
        (mapcar
          '(lambda (x)
            (cond
              ((wcmatch lay_name (strcat "LP-PLNT_TREE-SHT" x))
                (setq lay_list1 (cons lay_name lay_list1))
              )
              ((wcmatch lay_name (strcat "LP-PLNT_SHRB-SHT" x))
                (setq lay_list2 (cons lay_name lay_list2))
              )
            )
          )
          '("#" "##" "###")
        )
      )
      (if lay_list1
        (setq last_lay1 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list1) '>)))
        (setq last_lay1 0)
      )
      (if lay_list2
        (setq last_lay2 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list2) '>)))
        (setq last_lay2 0)
      )
      (initget "Tree Shrb 2")
      (if (not (setq what (getkword "\nIncrement numbering the layer [Tree/Shrb/2] <2>: "))) (setq what "2"))
      (cond
        ((eq what "Tree")
          (prompt (strcat "Color for the layer LP-PLNT_TREE-SHT" (itoa (1+ last_lay1))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_TREE-SHT" (itoa (1+ last_lay1)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Trees (Sht " (itoa (1+ last_lay1)) ")"))
        )
        ((eq what "Shrb")
          (prompt (strcat "Color for the layer LP-PLNT_SHRB-SHT" (itoa (1+ last_lay2))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_SHRB-SHT" (itoa (1+ last_lay2)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Shrb (Sht " (itoa (1+ last_lay2)) ")"))
        )
        (T
          (prompt (strcat "Color for the layer LP-PLNT_TREE-SHT" (itoa (1+ last_lay1)) " and layer LP-PLNT_SHRB-SHT" (itoa (1+ last_lay2))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_TREE-SHT" (itoa (1+ last_lay1)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Trees (Sht " (itoa (1+ last_lay1)) ")"))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_SHRB-SHT" (itoa (1+ last_lay2)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Shrb (Sht " (itoa (1+ last_lay2)) ")"))
        )
      )
      (prin1)
    )

  10. #10
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    Bruno,

    This is great. thanks for all of your help.

    Now I trying to add the 2nd version where I have more than 2 layers but it is not working.
    Code:
    (vl-load-com)
    (defun c:inc_layer2 ( / AcDoc lay lay_name flag lay_list1 lay_list2 lay_list3 lay_list4 last_lay1 last_lay2 last_lay3 last_lay4 what col layerObj)
      (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (while (setq lay (tblnext "LAYER" (not flag)))
        (setq lay_name (strcase (cdr (assoc 2 lay))) flag T)
        (mapcar
          '(lambda (x)
            (cond
              ((wcmatch lay_name (strcat "LP-PLNT_SHRB-SHT" x))
                (setq lay_list1 (cons lay_name lay_list1))
              )
              ((wcmatch lay_name (strcat "LP-PLNT_GCVR-PATT-SHT" x))
                (setq lay_list2 (cons lay_name lay_list2))
    	  ) 
    	  ((wcmatch lay_name (strcat "LP-PLNT_GCVR-POLY-SHT" x))
                (setq lay_list3 (cons lay_name lay_list3))
              )
    	  ((wcmatch lay_name (strcat "LP-PLNT_TURF-PATT-SHT" x))
                (setq lay_list4 (cons lay_name lay_list4))
              )
            )
          )
          '("#" "##" "###")
        )
      )
      (if lay_list1
        (setq last_lay1 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list1) '>)))
        (setq last_lay1 0)
      )
      (if lay_list2
        (setq last_lay2 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list2) '>)))
        (setq last_lay2 0)
      )
      (if lay_list3
        (setq last_lay3 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list3) '>)))
        (setq last_lay3 0)
      )
      (if lay_list4
        (setq last_lay4 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 17))) lay_list4) '>)))
        (setq last_lay4 0)
      )
      (initget "Shrub Gcvr gcvrP Turf All")
      (if (not (setq what (getkword "\nIncrement numbering the layer [Shrub/Gcvr/gcvrP/Turf/All] <All>: "))) (setq what "All"))
      (cond
        ((eq what "Shrub")
          (prompt (strcat "Color for the layer LP-PLNT_SHRB-SHT" (itoa (1+ last_lay1))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_SHRB-SHT" (itoa (1+ last_lay1)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Shrubs (Sht " (itoa (1+ last_lay1)) ")"))
        )
        ((eq what "Gcvr")
          (prompt (strcat "Color for the layer LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Ground cover hatching (Sht " (itoa (1+ last_lay2)) ")"))
        )
        ((eq what "gcvrP")
          (prompt (strcat "Color for the layer LP-PLNT_GCVR-POLY-SHT" (itoa (1+ last_lay3))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_GCVR-POLY-SHT" (itoa (1+ last_lay3)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Ground cover poly (Sht " (itoa (1+ last_lay3)) ")"))
        )
        ((eq what "Turf")
          (prompt (strcat "Color for the layer LP-PLNT_TURF-PATT-SHT" (itoa (1+ last_lay4))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_TURF-PATT-SHT" (itoa (1+ last_lay4)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Turf hatching (Sht " (itoa (1+ last_lay4)) ")"))
        (T
          (prompt (strcat "Color for the layer LP-PLNT_SHRB-SHT" (itoa (1+ last_lay1)) " and layer LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2) " and layer LP-PLNT_GCVR-POLY-SHT" (itoa (1+ last_lay3) " and layer LP-PLNT_TURF-PATT-SHT" (itoa (1+ last_lay4))))
          (terpri)
          (while (not (setq col (acad_colordlg 7 nil))))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_SHRB-SHT" (itoa (1+ last_lay1)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Shrubs (Sht " (itoa (1+ last_lay1)) ")"))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Ground cover hatching (Sht " (itoa (1+ last_lay2)) ")"))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_GCVR-POLY-SHT" (itoa (1+ last_lay3)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Ground cover hatching (Sht " (itoa (1+ last_lay3)) ")"))
          (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat "LP-PLNT_TURF-PATT-SHT" (itoa (1+ last_lay4)))))
          (vlax-put layerObj 'color col)
          (vla-put-Description layerObj (strcat "Plant and landscape material: Turf hatching (Sht " (itoa (1+ last_lay4)) ")"))
        )
      )
      (prin1)
    )
    Last edited by Opie; 2022-04-29 at 03:55 PM. Reason: Please use [code] tags instead of [quote] tags for code display

Page 1 of 2 12 LastLast

Similar Threads

  1. Door Numbering based on Room Numbering
    By heather.leibman in forum Revit Architecture - General
    Replies: 5
    Last Post: 2011-12-05, 07:59 PM
  2. Replies: 12
    Last Post: 2010-01-08, 07:49 PM
  3. Create Layer name using the Drawing name
    By g_wong in forum AutoLISP
    Replies: 14
    Last Post: 2009-01-09, 02:25 AM
  4. Replies: 2
    Last Post: 2007-12-17, 09:10 PM
  5. Auto Increment Numbering for AutoCAD LT.
    By zoomharis in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2007-08-21, 05:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •