Author Topic: Help updating a lisp  (Read 667 times)

0 Members and 1 Guest are viewing this topic.

cadd4la

  • Newt
  • Posts: 27
Help updating a lisp
« on: February 17, 2023, 11:43:37 AM »
Hello everyone,

I am looking for help updating this lisp.

I need it to create a layer by picking an item(s) on that layer, using the same name of that existing layer but adding ABC~-CHGD and a number starting with 1 and advancing by 1 at the end of it, then asking do I want to use the same layer color or select a new layer color. when I have picked all the items that I need to change, it places them on that new layer. If I use the command again it knows to go to the next unused number if I have picked that original layer again.

The way the code is written now, it creates a new layer for every item that is picked.

Code: [Select]
(defun c:LAYCHA (/ i l n s x c y r d e)
  (if
    (and (setq s (ssget "_:L" '((8 . "~*ABC~-CHGD0"))))
         (setq r
                (getstring
                  "\nSpeficy a number from 01-10 <enter to exit> :"
  ;;;;"\nSpeficy a number from [1-9] or [01-09] <enter to exit> :"
                )
         )
         (or (numberp (read r))
             (progn (princ "\nInvalid input!. Please try again.") nil)
         )
         (setq y (and (= (strlen r) 2) (wcmatch r "0*"))
               c (acad_colordlg 256)
         )
    )
     (repeat (setq i (sslength s))
       (setq x (ssname s (setq i (1- i)))
             e (entget x)
             l (assoc 8 e)
             n (strcat (cdr l) "_ABC~-CHGD" r)
             d (list '(290 . 1) (cons 62 c))
             r (1+ (atoi r))
             r (if (and y (< r 10))
                 (strcat "0" (itoa r))
                 (itoa r)
               )
       )
       (if (tblsearch "LAYER" n)
         (entmod (append (entget (tblobjname "LAYER" n)) d))
         (entmake (append (list '(0 . "LAYER")
                                '(100 . "AcDbSymbolTableRecord")
                                '(100 . "AcDbLayerTableRecord")
                                (cons 2 n)
                                '(70 . 0)
                          )
                          d
                  )
         )
       )
       (entmod (subst (cons 8 n) l e))
     )
  )
  (princ)
)

Thanks,
Windows 10 x64 - AutoCAD 2023