HHL Posted September 14, 2018 Posted September 14, 2018 (edited) Hello! I’m trying to do a lisp which runs through all lines and sorts them by color, so the heaviest color ends up on top. This works fine for when there are lines to move but if the selection is empty (in case no green lines exists in the drawing for example) the script stops and waits for an selection but I want it to just move on in case no lines exist. This is for cleaning up dwg exports from Revit so sometimes all colors needs to be sorted, sometimes on 3 or 4 depending on which drawing is exported. (defun ssfilter-by-color (color / lay layers) ;; Get all the layer names whi?ch are set to the color (setq lay (tblnext "LAYER" t) ;Get the 1st layer layers "" ;Initialize the layer names filter string ) (while lay ;Step through all layers ;; Check if current layer is set to color (if (= (cdr (assoc 62 lay)) color) (setq layers (strcat "," (cdr (assoc 2 lay)) layers)) ;Add to filter string ) (setq lay (tblnext "LAYER")) ;Get the next layer ) (if (= layers "") (list (cons 62 color)) (list '(-4 . "<OR") '(-4 . "<AND") (cons 8 (substr layers 2)) '(62 . 256) '(-4 . "AND>") (cons 62 color) '(-4 . "OR>") ) ) ) (sssetfirst nil (ssget "_x" (ssfilter-by-color 7))) ;;nr=indexcolor (command "_draworder" "_B") (sssetfirst nil (ssget "_x" (ssfilter-by-color 3))) (command "_draworder" "_B") (sssetfirst nil (ssget "_x" (ssfilter-by-color 1))) (command "_draworder" "_B") (sssetfirst nil (ssget "_x" (ssfilter-by-color 4))) (command "_draworder" "_B") (princ) Edited September 14, 2018 by HHL Quote
Roy_043 Posted September 15, 2018 Posted September 15, 2018 Try: (defun ssfilter-by-color (color / lay layers) ;; Get all the layer names which are set to the color (setq lay (tblnext "LAYER" t) ; Get the 1st layer layers "" ; Initialize the layer names filter string ) (while lay ; Step through all layers ;; Check if current layer is set to color (if (= (cdr (assoc 62 lay)) color) (setq layers (strcat "," (cdr (assoc 2 lay)) layers)) ; Add to filter string ) (setq lay (tblnext "LAYER")) ; Get the next layer ) (if (= layers "") (list (cons 62 color)) (list '(-4 . "<OR") '(-4 . "<AND") (cons 8 (substr layers 2)) '(62 . 256) '(-4 . "AND>") (cons 62 color) '(-4 . "OR>") ) ) ) (defun ssfilter-by-space () (list (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")) '(-4 . "<NOT") '(-4 . "<AND") '(0 . "VIEWPORT") '(69 . 1) '(-4 . "AND>") '(-4 . "NOT>") ) ) (defun c:DrawOrderByColor ( / spc ss) (setq spc (ssfilter-by-space)) (foreach aci '(7 3 1 4) (if (setq ss (ssget "_X" (append spc (ssfilter-by-color aci)))) (command "_draworder" ss "" "_back") ) ) (princ) ) (c:DrawOrderByColor) The ssfilter-by-color function was not modified. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.