(vl-load-com)
(defun c:classify ( / ss ssl index obj color linetype linetypescale str layertable newlayername)
(princ "\n select object to classify")
(setq layertable (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(if (setq ss (ssget))
(progn
(setq ssl 0)
(setq ssl (sslength ss))
(setq index 0)
(setq str "")
(repeat ssl
(setq obj (vlax-ename->vla-object (cdr (assoc -1 (entget (ssname ss index))))))
(setq color (vla-get-color obj))
(if (= color 256) ; if by layer
(setq color (cdr (assoc 62 (tblsearch "LAYER" (vla-get-layer obj)))))
)
(setq color (vl-princ-to-string color))
(setq linetype (vl-princ-to-string (vla-get-linetype obj)))
(if (= linetype "ByLayer") ; if by layer
(setq linetype (cdr (assoc 6 (tblsearch "LAYER" (vla-get-layer obj)) ) ) )
)
(setq linetype (vl-princ-to-string linetype))
(setq linetypescale (vl-princ-to-string (vla-get-linetypescale obj)))
(setq str (strcat "color-" color "_lt-" linetype "_lts-" linetypescale))
(if (= (tblsearch "LAYER" str) nil)
(progn
(setq newlayername (vla-add layertable str))
(vla-put-color newlayername color)
(vla-put-linetype newlayername linetype)
;(vla-put-linetypescale newlayername linetypescale)
(vlax-put-property obj 'layer str)
(vla-put-color obj 256)
(vla-put-linetype obj "ByLayer")
); end of progn
(progn
(setq newlayername (vla-item layertable str))
(vlax-put-property obj 'layer str)
(vla-put-color obj 256)
(vla-put-linetype obj "ByLayer")
); end of progn
); end of if
(setq index (+ index 1))
);end of repeat
);end of progn
);end of if
(princ)
);end of defun
how about approach like this.
- code updated, layer cannot have linetype scale value. my mistake.
works like below