Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Make a layer name with increment numbering

  1. #11
    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

    You were close, but in your code there are missing or misplaced closing parentheses.
    An error also with the function (substr "string" "starting character position") where the position was badly adapted.
    Here is your corrected version:
    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 22))) lay_list2) '>)))
        (setq last_lay2 0)
      )
      (if lay_list3
        (setq last_lay3 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 22))) lay_list3) '>)))
        (setq last_lay3 0)
      )
      (if lay_list4
        (setq last_lay4 (car (vl-sort (mapcar '(lambda (x) (atoi (substr x 22))) 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)) ", layer LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2)) ", 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)
    )
    Another version which may seem more complex to you to understand but where you can (by modifying the correlated lists), apply more layers without repeating the add layer function many times.
    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 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)
            (mapcar
              '(lambda (s l)
                (if (wcmatch lay_name (strcat s x))
                  (set (read l) (cons lay_name (eval (read l))))
                )
               )
              (list "LP-PLNT_SHRB-SHT" "LP-PLNT_GCVR-PATT-SHT" "LP-PLNT_GCVR-POLY-SHT" "LP-PLNT_TURF-PATT-SHT")
              (list "lay_list1" "lay_list2" "lay_list3" "lay_list4")
            )
          )
          '("#" "##" "###")
        )
      )
      (mapcar
        '(lambda (s ll l)
          (if (eval (read l))
            (set (read ll) (car (vl-sort (mapcar '(lambda (x) (atoi (substr x (1+ (strlen s))))) (eval (read l))) '>)))
            (set (read ll) 0)
          )
         )
        (list "LP-PLNT_SHRB-SHT" "LP-PLNT_GCVR-PATT-SHT" "LP-PLNT_GCVR-POLY-SHT" "LP-PLNT_TURF-PATT-SHT")
        (list "last_lay1" "last_lay2" "last_lay3" "last_lay4")
        (list "lay_list1" "lay_list2" "lay_list3" "lay_list4")
      )
      (initget "Shrub Gcvr gcvrP Turf All")
      (if (not (setq what (getkword "\nIncrement numbering the layer [Shrub/Gcvr/gcvrP/Turf/All] <All>: "))) (setq what "All"))
      (
        (lambda (l / col)
          (while l
            (if (not col)
              (progn
                (if (eq what "All")
                  (prompt
                    (strcat
                      "Color for the layer LP-PLNT_SHRB-SHT" (itoa (1+ last_lay1))
                      ", layer LP-PLNT_GCVR-PATT-SHT" (itoa (1+ last_lay2))
                      ", layer LP-PLNT_GCVR-POLY-SHT" (itoa (1+ last_lay3))
                      " and layer LP-PLNT_TURF-PATT-SHT" (itoa (1+ last_lay4))
                    )
                  )
                  (prompt (strcat "Color for the layer " (car l) (itoa (1+ (cadr l)))))
                )
                (terpri)
                (while (not (setq col (acad_colordlg 7 nil))))
              )
            )
            (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat (car l) (itoa (1+ (cadr l))))))
            (vlax-put layerObj 'color col)
            (vla-put-Description layerObj (strcat (caddr l) (itoa (1+ (cadr l))) ")"))
            (setq l (cdddr l))
          )
        )
        (cond
          ((eq what "Shrub") (append '("LP-PLNT_SHRB-SHT") (list last_lay1) '("Plant and landscape material: Shrubs (Sht ")))
          ((eq what "Gcvr") (append '("LP-PLNT_GCVR-PATT-SHT") (list last_lay2) '("Plant and landscape material: Ground cover hatching (Sht ")))
          ((eq what "gcvrP") (append '("LP-PLNT_GCVR-POLY-SHT") (list last_lay3) '("Plant and landscape material: Ground cover poly (Sht ")))
          ((eq what "Turf") (append '("LP-PLNT_TURF-PATT-SHT") (list last_lay4) '("Plant and landscape material: Turf hatching (Sht ")))
          (T
            (append
              '("LP-PLNT_SHRB-SHT") (list last_lay1) '("Plant and landscape material: Shrubs (Sht ")
              '("LP-PLNT_GCVR-PATT-SHT") (list last_lay2) '("Plant and landscape material: Ground cover hatching (Sht ")
              '("LP-PLNT_GCVR-POLY-SHT") (list last_lay3) '("Plant and landscape material: Ground cover poly (Sht ")
              '("LP-PLNT_TURF-PATT-SHT") (list last_lay4) '("Plant and landscape material: Turf hatching (Sht ")
            )
          )
        )
      )
      (prin1)
    )

  2. #12
    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 for fixing the code and providing an easier way to add additional layers if I need to.

    Cadd4la

  3. #13
    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,

    I'm having a problem with your second code and adding a list for 6 layers.

    When I load the code after I add two new layers I get ; error: malformed list on input

    If I add );<-- the code will load but when I select "All" I get bad argument type: numberp: nil

    Code:
    (vl-load-com)
    (defun c:inc_layer6  ( / AcDoc lay lay_name flag lay_list1 lay_list2 lay_list3 lay_list4 lay_list5 lay_list6 last_lay1 last_lay2 last_lay3 last_lay4 last_lay5 last_lay6 what 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)
            (mapcar
              '(lambda (s l)
                (if (wcmatch lay_name (strcat s x))
                  (set (read l) (cons lay_name (eval (read l))))
                )
               )
              (list "LG-TOPO_SPOT-SHT" "LG-ANNO_ALGN_ADJ-SHT" "LG-DRAN_SHRB-06IN-SHT" "LG-DRAN_GRVL-06IN-SHT" "LG-DRAN_TURF-06IN-SHT" "LG-PIPE_04IN-SHT")
              (list "lay_list1" "lay_list2" "lay_list3" "lay_list4" "lay_list5" "lay_list6")
            )
          )
          '("#" "##" "###")
        )
      )
      (mapcar
        '(lambda (s ll l)
          (if (eval (read l))
            (set (read ll) (car (vl-sort (mapcar '(lambda (x) (atoi (substr x (1+ (strlen s))))) (eval (read l))) '>)))
            (set (read ll) 0)
          )
         )
        (list "LG-TOPO_SPOT-SHT" "LG-ANNO_ALGN_ADJ-SHT" "LG-DRAN_SHRB-06IN-SHT" "LG-DRAN_GRVL-06IN-SHT" "LG-DRAN_TURF-06IN-SHT" "LG-PIPE_04IN-SHT")
        (list "last_lay1" "last_lay2" "last_lay3" "last_lay4" "last_lay5" "last_lay6")
        (list "lay_list1" "lay_list2" "lay_list3" "lay_list4" "lay_list5" "lay_list6")
      )
      (initget "Spot aLgn sHrb Grvl Turf Pipe4in All")
      (if (not (setq what (getkword "\nIncrement numbering the layer [Spot/aLgn/sHrb/Grvl/Turf/Pipe4in/All] <All>: "))) (setq what "All"))
      (
       (lambda (l / col)
          (while l
            (if (not col)
              (progn
               (if (eq what "All")
                  (prompt
                    (strcat
                      "Color for the layer LG-TOPO_SPOT-SHT" (itoa (1+ last_lay1))
                      ", layer LG-ANNO_ALGN_ADJ-SHT" (itoa (1+ last_lay2))
                      ", layer LG-DRAN_SHRB-06IN-SHT" (itoa (1+ last_lay3))
                      ", layer LG-DRAN_GRVL-06IN-SHT" (itoa (1+ last_lay4))
                      ", layer LG-DRAN_TURF-06IN-SHT" (itoa (1+ last_lay5))
                      " and layer LG-PIPE_04IN-SHT" (itoa (1+ last_lay6))
                    )
                  )
    );<--
    );<--
                  (prompt (strcat "Color for the layer " (car l) (itoa (1+ (cadr l)))))
                )
                (terpri)
                (while (not (setq col (acad_colordlg 7 nil))))
              )
            )
            (setq layerObj (vla-add (vla-get-layers AcDoc) (strcat (car l) (itoa (1+ (cadr l))))))
            (vlax-put layerObj 'color col)
            (vla-put-Description layerObj (strcat (caddr l) (itoa (1+ (cadr l))) ")"))
            (setq l (cdddr l))
          )
        )
        (cond
          ((eq what "Spot") (append '("LG-TOPO_SPOT-SHT") (list last_lay1) '("Topographic feature: Spot elevation (Sht ")))
          ((eq what "aLgn") (append '("LG-ANNO_ALGN_ADJ-SHT") (list last_lay2) '("Annotation: Alignment (Sht ")))
          ((eq what "sHrb") (append '("LG-DRAN_SHRB-06IN-SHT") (list last_lay3) '("Drains: 6" shrub inlet (Sht ")))
          ((eq what "Grvl") (append '("LG-DRAN_GRVL-06IN-SHT") (list last_lay4) '("Drains: 6" gravel inlet (Sht ")))
          ((eq what "Turf") (append '("LG-DRAN_TURF-06IN-SHT") (list last_lay5) '("Drains: 6" turf inlet (Sht ")))
          ((eq what "Pipe4in") (append '("LG-PIPE_04IN-SHT") (list last_lay6) '("Piping: 4" Pipe line (Sht ")))
          (T
            (append
              '("LG-TOPO_SPOT-SHT") (list last_lay1) '("Topographic feature: Spot elevation (Sht ")
              '("LG-ANNO_ALGN_ADJ-SHT") (list last_lay2) '("Annotation: Alignment (Sht ")
              '("LG-DRAN_SHRB-06IN-SHT") (list last_lay3) '("Drains: 6" shrub inlet (Sht ")
              '("LG-DRAN_GRVL-06IN-SHT") (list last_lay4) '("Drains: 6" gravel inlet (Sht ")
              '("LG-DRAN_TURF-06IN-SHT") (list last_lay5) '("Drains: 6" turf inlet (Sht ")
              '("LG-PIPE_04IN-SHT") (list last_lay6) '("Piping: 4" Pipe line (Sht ")
            )
          )
        )
      )
    );<--
    );<--
      (prin1)
    )
    Thanks,

    Cadd4la
    Last edited by cadd4la; 2022-05-03 at 02:05 AM.

  4. #14
    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

    Don't add parenthesis, is good wihout. Your error is in the Description of layer: if you want use " (for I suppose inch) use before the anti-slash " . With this the double quote is not evalued.
    Exemple:
    Code:
    ((eq what "sHrb") (append '("LG-DRAN_SHRB-06IN-SHT") (list last_lay3) '("Drains: 6\" shrub inlet (Sht ")))

  5. #15
    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, that fix the code.

    Again, I'm very grateful for all of your help to do this code for me.

    Regards,

    Cadd4la

  6. #16
    Member
    Join Date
    2016-05
    Posts
    19
    Login to Give a bone
    0

    Default Re: Make a layer name with increment numbering

    this lisp will create the layer name with a sequence number as much as you repeat the command.
    the command is: addlayerno OR adlp
    Code:
    ;;; this lisp that will create a new layer named LP-PLNT_TREE-SHT* (you can chenge the layer name)
    ;;; (* = a number starting with 1 if the layer doesn't exist already
    ;;; and will continue to increase if the command is repeaed 1, 2, 3, 4, etc.
    ;;; the sequence will be from the biggest number from thr right.
    
    
    (vl-load-com) ; load ActiveX support
    
    (setq *acadobj*(vlax-get-acad-object))
    (setq *doc_ly*(vla-get-activedocument *acadobj*))
    (setq *layers*(vla-get-Layers *doc_ly*))
    
    ;;;layers name list
    (defun layers:name:list ( / ln)
    (vlax-for name
    *layers*
    (setq ln (cons (vla-get-name name) ln))      
    )
    (reverse ln)
    )
    
    ;;;create layer
    (defun mk:layer (name color Linetype / clay nlayer)
    (setq clay (getvar "clayer"))
    (setvar "clayer" "0")
    (setq nlayer(vlax-invoke-method *layers* 'Add name))
    (vlax-put-property nlayer 'Freeze 0)
    (vlax-put-property nlayer 'Lock 0)
    (vlax-put-property nlayer 'LayerOn -1)
    (if (= color nil)(setq color "7")(princ))
    (vlax-put-property nlayer 'color color)
    (if (= Linetype nil) (setq Linetype "Continuous") (princ))
    (vlax-put-property nlayer 'Linetype Linetype)
    (vla-Regen *doc_ly* acAllViewports)
    (setvar "clayer" clay)
    nlayer
    )
    
    (defun add:layer (layer_name color / alfbt ly_no lrg_no ad_lyr_name)
    
    (setq ly_n(layers:name:list))
    
    (setq alfbt "-_QWERTYUIOPASDFGHJKLZXCVBNM")
    
    (setq ly_no(mapcar '(lambda (x) 
    (vl-string-trim alfbt (strcase x) )
    ) 
    ly_n
    ))
    
    (setq lrg_no(apply 'max (mapcar 'atoi ly_no)))
    
    (setq ad_lyr_name (strcat layer_name (rtos(1+ lrg_no)2 0)))
    
    (mk:layer ad_lyr_name color nil)
    )
    
    (defun c:addlayerno (/ color_no)
    
    (setq color_no (getint "\nEnter Color Number:"))
    
    (if (eq color_no nil)(setq color_no 7)(princ))
    
    (add:layer "LP-PLNT_TREE-SHT" color_no)
    
    )
    
    (defun c:adlp() (c:addlayerno))

Page 2 of 2 FirstFirst 12

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
  •