avfy Posted March 19, 2021 Posted March 19, 2021 Hoping a lisp guru can help me out with what should be a pretty simple routine. I have many many drawings that have 3 lines which are specific lengths(3, 5, and 5.5) that need to be deleted. They also have lines which are color red that need to be deleted. Can someone write a lisp which deletes all lines of these specific lengths, then deletes all lines that are red in color? Thank you so much for you help Quote
rkmcswain Posted March 19, 2021 Posted March 19, 2021 Are the lines actually assigned the color RED, or is their color actually BYLAYER and the layer they reside on is set to RED? Regarding the line lengths, are you specifying 2D length or 3D length? Here is a start (untested) (defun 2ddist (p1 p2) (distance (list (car p1) (cadr p1) 0.0) (list (car p2) (cadr p2) 0.0) ) ) ;; 2D length considered only (defun c:foo ( / ALL END ENT I RES START) (setq all (ssget "_X" '((0 . "LINE"))) i 0) (repeat (sslength all) (setq ent (entget (ssname all i))) (setq start (cdr (assoc 10 ent))) (setq end (cdr (assoc 11 ent))) (setq res (2ddist start end)) (if (or (equal res 5.0 0.0001) (equal res 5.5 0.0001) (equal res 3.0 0.0001) ) (entdel (ssname all i)) ) (setq i (1+ i)) ) ) Quote
avfy Posted March 19, 2021 Author Posted March 19, 2021 All lines are on layer 0, the lines that need to be removed by color are assigned red directly. Lengths are 2D. Thanks for your help Quote
rkmcswain Posted March 19, 2021 Posted March 19, 2021 ;; Delete Red Lines (color red, not color bylayer on a red layer) (defun c:fox ( / sset) (setq sset (ssget "_X" '((0 . "LINE")(62 . 1)))) (vl-cmdf "._erase" sset "") (princ) ) Quote
avfy Posted March 19, 2021 Author Posted March 19, 2021 Forgive my ignorance, but how would I combine these 2 into a single lisp? Also, is the color red defined by "1" in: (setq sset (ssget "_X" '((0 . "LINE")(62 . 1)))) 1 being the index color? Thanks again for your help Quote
avfy Posted March 19, 2021 Author Posted March 19, 2021 Sorry but I just realized I gave the wrong information about the color portion of the lisp. I actually need it to delete EVERYTHING that is red, not just lines but lines and text. Quote
avfy Posted March 19, 2021 Author Posted March 19, 2021 Actually I figured it out, just had to do this: (setq sset (ssget "_X" '((62 . 1)))) And I answered my own question that yes 1 is in fact the index color. Only part I can't figure out now is combining the 2 lisps to run as a single command. Quote
rkmcswain Posted March 19, 2021 Posted March 19, 2021 34 minutes ago, avfy said: Sorry but I just realized I gave the wrong information about the color portion of the lisp. I actually need it to delete EVERYTHING that is red, not just lines but lines and text. "lines and text" is not the same as "everything". For red lines and text (ssget "X" '((-4 . "<OR")(0 . "LINE")(0 . "TEXT")(-4 . "OR>")(62 . 1))) For red everything (ssget "X" '((62 . 1))) Quote
Tharwat Posted March 19, 2021 Posted March 19, 2021 1 hour ago, rkmcswain said: For red lines and text (ssget "X" '((-4 . "<OR")(0 . "LINE")(0 . "TEXT")(-4 . "OR>")(62 . 1))) You do not need to use the operand OR so the following is enough. (ssget "_X" '((0 . "LINE,TEXT") (62 . 1))) Quote
avfy Posted March 22, 2021 Author Posted March 22, 2021 Thanks everyone. Both of the scripts work great on their own but does anyone know how I could combine them into a single command? Quote
ronjonp Posted March 22, 2021 Posted March 22, 2021 3 hours ago, avfy said: Thanks everyone. Both of the scripts work great on their own but does anyone know how I could combine them into a single command? Maybe this ? (defun c:foo (/ d el s) (if (setq s (ssget "_X" '((0 . "LINE,TEXT") (62 . 1)))) (foreach e (mapcar 'cadr (ssnamex s)) (if (= "TEXT" (cdr (assoc 0 (setq el (entget e))))) (entdel e) (progn (setq d (distance (cdr (assoc 10 el)) (cdr (assoc 11 el)))) (foreach x '(3. 5. 5.5) (and (equal d x 1e-4) (entdel e))) ) ) ) ) (princ) ) Quote
Tharwat Posted March 22, 2021 Posted March 22, 2021 Nice one Ron, Why did not you use vl-some instead of foreach to avoid the iteration three times with every line? Quote
avfy Posted March 22, 2021 Author Posted March 22, 2021 (edited) 19 minutes ago, ronjonp said: Maybe this ? (defun c:foo (/ d el s) (if (setq s (ssget "_X" '((0 . "LINE,TEXT") (62 . 1)))) (foreach e (mapcar 'cadr (ssnamex s)) (if (= "TEXT" (cdr (assoc 0 (setq el (entget e))))) (entdel e) (progn (setq d (distance (cdr (assoc 10 el)) (cdr (assoc 11 el)))) (foreach x '(3. 5. 5.5) (and (equal d x 1e-4) (entdel e))) ) ) ) ) (princ) ) I ran it and it's only removing the red text. Red lines and the other 3 lengths are still there. Edited March 22, 2021 by avfy Quote
ronjonp Posted March 22, 2021 Posted March 22, 2021 23 minutes ago, Tharwat said: Nice one Ron, Why did not you use vl-some instead of foreach to avoid the iteration three times with every line? Keeping it 'vanilla' .. and it's only 3 items. Quote
ronjonp Posted March 22, 2021 Posted March 22, 2021 (edited) 41 minutes ago, avfy said: I ran it and it's only removing the red text. Red lines and the other 3 lengths are still there. Post a sample drawing. Also .. are these lines that have the 3 5 and 5.5 lengths colors other than red by object? Or do you want to remove ALL red lines ? Edited March 22, 2021 by ronjonp Quote
avfy Posted March 22, 2021 Author Posted March 22, 2021 (edited) I want to remove anything that is red. Just so happens that the only things that are red are text and lines. Edited March 22, 2021 by avfy Quote
ronjonp Posted March 22, 2021 Posted March 22, 2021 (edited) 6 minutes ago, avfy said: delete (2).dwg 28.54 kB · 0 downloads I want to remove anything that is red. Just so happens that the only things that are red are text and lines. Then simply: (defun c:foo (/ s) ;; For lines and text, remove '(0 . "LINE,TEXT")' below to get everything. (if (setq s (ssget "_X" '((0 . "LINE,TEXT") (62 . 1)))) (foreach e (mapcar 'cadr (ssnamex s)) (entdel e)) ) (princ) ) The title of your post has length requirements so that was how I tailored the original code. Are you familiar with the filter command? Edited March 22, 2021 by ronjonp Quote
avfy Posted March 22, 2021 Author Posted March 22, 2021 I'm sorry, I guess I didn't word it correctly. I need to remove all lines that are 3, 5, and 5.5 in length(regardless of color or layer) and in addition ALL objects that are red Quote
ronjonp Posted March 22, 2021 Posted March 22, 2021 (edited) 21 minutes ago, avfy said: I'm sorry, I guess I didn't word it correctly. I need to remove all lines that are 3, 5, and 5.5 in length(regardless of color or layer) and in addition ALL objects that are red Take three (defun c:foo (/ d el s) ;; All lines and text (if (setq s (ssget "_X" '((0 . "LINE,TEXT")))) (foreach e (mapcar 'cadr (ssnamex s)) ;; It's red .. delete it (if (= 1 (cdr (assoc 62 (setq el (entget e))))) (entdel e) ;; It's not red and it's a line (cond ((= "LINE" (cdr (assoc 0 el))) ;; Get the length (setq d (distance (cdr (assoc 10 el)) (cdr (assoc 11 el)))) ;; Check if it matches one of the lengths and delete it (foreach x '(3. 5. 5.5) (and (equal d x 1e-4) (entdel e))) ) ) ) ) ) (princ) ) Edited March 22, 2021 by ronjonp Quote
avfy Posted March 22, 2021 Author Posted March 22, 2021 Hallelujah it works! Thanks so much for all your help and patience. 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.