Author Topic: I want to send objects to each layer based on the color ?  (Read 1459 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 291
I want to send objects to each layer based on the color ?
« on: June 18, 2020, 11:40:27 AM »
hi frends ,
pls i need some help again sorry ~
this code is   to  send  layer based on object's color
but  This does not work for hatch objects  and  bylayer object

how can i do that ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:c2l ()
  2.   (setq cmdecho (getvar "CMDECHO"))
  3.   (setvar "CMDECHO" 0)
  4.   (command "UNDO" "G")
  5.   ;
  6.   (setq sset (ssget))
  7.   (if (/= sset nil)
  8.     (progn
  9.       (setq num (sslength sset) itm 0)
  10.       (while (< itm num)
  11.         (setq hnd (ssname sset itm))
  12.         (setq ent (entget hnd))
  13.         (setq col (cdr (assoc 62 ent)))
  14.         (if (/= col nil)
  15.           (if (and (> col 0)(< col 256))
  16.             (progn
  17.               (setq lay (strcat "color-" (itoa col)))
  18.               (if (= (tblsearch "LAYER" lay) nil)
  19.                 (command "_LAYER" "_N" lay "_C" col lay "")
  20.               )
  21.               (command "_CHPROP" hnd "" "_LA" lay "_C" "BYLAYER" "")
  22.             )
  23.           )
  24.         )
  25.         (setq itm (1+ itm))
  26.       )
  27.       (princ ", Done.")
  28.     )
  29.   )
  30.   ;
  31.   (setq sset nil)
  32.   (command "UNDO" "E")
  33.   (setvar "CMDECHO" cmdecho)
  34.   (princ)
  35. )


EDIT (John): Added code tags.
« Last Edit: June 18, 2020, 01:26:07 PM by dussla »

ronjonp

  • Needs a day job
  • Posts: 7527
Re: I want to send objects to each layer based on the color ?
« Reply #1 on: June 18, 2020, 02:34:10 PM »
Here's a quickie:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ c e l n s)
  2.   ;; RJP » 2020-06-18
  3.   (if (setq s (ssget ":L"))
  4.     (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  5.       (setq l (tblobjname "layer" (setq n (cdr (assoc 8 (entget e))))))
  6.       (setq c (cdr (cond ((assoc 62 (entget e)))
  7.                          ((assoc 62 (entget (tblobjname "layer" n))))
  8.                    )
  9.               )
  10.       )
  11.       (or (tblobjname "layer" (setq n (strcat "color-" (itoa c))))
  12.           (entmakex (append (entget l) (list (cons 2 n))))
  13.       )
  14.       (entmod (append (entget e) (list (cons 8 n))))
  15.     )
  16.   )
  17.   (princ)
  18. )
« Last Edit: June 18, 2020, 03:06:29 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 291
Re: I want to send objects to each layer based on the color ?
« Reply #2 on: June 18, 2020, 10:48:25 PM »
Here's a quickie:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ c e l n s)
  2.   ;; RJP » 2020-06-18
  3.   (if (setq s (ssget ":L"))
  4.     (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  5.       (setq l (tblobjname "layer" (setq n (cdr (assoc 8 (entget e))))))
  6.       (setq c (cdr (cond ((assoc 62 (entget e)))
  7.                          ((assoc 62 (entget (tblobjname "layer" n))))
  8.                    )
  9.               )
  10.       )
  11.       (or (tblobjname "layer" (setq n (strcat "color-" (itoa c))))
  12.           (entmakex (append (entget l) (list (cons 2 n))))
  13.       )
  14.       (entmod (append (entget e) (list (cons 8 n))))
  15.     )
  16.   )
  17.   (princ)
  18. )
wow wow wow  perpect
simple code

always  thank you ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
thank you again ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ronjonp

  • Needs a day job
  • Posts: 7527
Re: I want to send objects to each layer based on the color ?
« Reply #3 on: June 19, 2020, 02:00:05 PM »
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC