Jump to content

Recommended Posts

Posted

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

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • avfy

    13

  • ronjonp

    9

  • rkmcswain

    3

  • Tharwat

    2

Top Posters In This Topic

Posted Images

Posted

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))
  )
)  

 

 

Posted

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

Posted
;; 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)
)

 

Posted

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

Posted

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.

Posted

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.

Posted
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)))

 

 

Posted
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)))

 

Posted

Thanks everyone. Both of the scripts work great on their own but does anyone know how I could combine them into a single command?

Posted
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)
)

 

Posted

Nice one Ron,

Why did not you use vl-some instead of foreach to avoid the iteration three times with every line?

Posted (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 by avfy
Posted
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.

Posted (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 by ronjonp
Posted (edited)

 

I want to remove anything that is red. Just so happens that the only things that are red are text and lines.

Edited by avfy
Posted (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? 

image.png.f54285a9c85427649dd209d2f64f211c.png

Edited by ronjonp
Posted

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

Posted (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 by ronjonp
Posted

Hallelujah it works! Thanks so much for all your help and patience. 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...