Author Topic: Change Selected Objects Layer Color - Looking for Routine  (Read 1462 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Change Selected Objects Layer Color - Looking for Routine
« on: June 03, 2015, 04:26:04 PM »
I am looking to find a Lisp routine that will allow me to change the color of a selected object, the layer color not just the object.

I want to just do the command and select the color I want and then select all the objects and have those layers change to the color I input.

I found the code below but it changes only the object, anyone know how to fix this code to make it do layers? or does anyone have a similar routine?

Code: [Select]
(defun c:chc (/ s i e)
  (if (not c)
    (setq c 1)
  )
  (while
    (not (< 0
            (setq
              c
               (cond
                 ((getint (strcat "\n Specify color between [1-255] ( "
                                  (itoa c)
                                  " ) : "
                          )
                  )
                 )
                 (t c)
               )
            )
            255
         )
    )
     (princ "\n Number of color must be between [1-255] ")
  )
  (if
    (and
      c
      (progn (princ "\n Select object to change their Layer colors ")
             (setq s (ssget "_:L"))
      )
    )
     (repeat (setq i (sslength s))
       (setq e (entget (ssname s (setq i (1- i)))))
       (entmod (append e (list (cons 62 c))))
     )
  )
  (princ)
)

Thanks!

kpblc

  • Bull Frog
  • Posts: 396
Re: Change Selected Objects Layer Color - Looking for Routine
« Reply #1 on: June 03, 2015, 04:28:00 PM »
Change (cons 62 c) to (cons 8 <LayerName>). And you nave to ask user fot layer name, of course.
Sorry for my English.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Change Selected Objects Layer Color - Looking for Routine
« Reply #2 on: June 03, 2015, 05:31:41 PM »
Try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:laycol ( / c e i l n s )
  2.     (if (and (setq c (acad_colordlg 1 nil))
  3.              (setq s (ssget))
  4.         )
  5.         (repeat (setq i (sslength s))
  6.             (if (not (member (setq n (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) l))
  7.                 (entmod
  8.                     (setq l (cons n l)
  9.                           e (entget (tblobjname "layer" n))
  10.                           e (subst (cons 62 c) (assoc 62 e) e)
  11.                     )
  12.                 )
  13.             )
  14.         )
  15.     )
  16.     (princ)
  17. )