Jump to content

Lisp to delete everything inside circles


Recommended Posts

Posted

Hi.

I need a lisp routine that deletes all the elements that are inside a circle.

I need to select many circles at the same time.

Please, can you help me?

Posted

Give this a try ... welcome to CadTutor!

(defun c:foo (/ _c2p _l a p r s)
  ;; RJP » 2020-12-18
  ;; Deletes items found within a selection of circles
  (defun _c2p (p r n / a i z)
    (setq a 0)
    (setq i (/ (* pi 2) n))
    (repeat n (setq z (cons (polar p (setq a (+ a i)) r) z)))
  )
  (defun _l (s)
    (if	s
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
    )
  )
  (cond	((setq s (_l (ssget '((0 . "CIRCLE")))))
	 (setq a (vlax-get-acad-object))
	 (foreach e s
	   (setq p (cdr (assoc 10 (entget e))))
	   (setq r (cdr (assoc 40 (entget e))))
	   (vlax-invoke a 'zoomcenter p (* r 2))
	   (foreach b (_l (ssget "_WP" (_c2p p r 100))) (entdel b))
	 )
	)
  )
  (progn)
)
(vl-load-com)

 

Posted

An alternative to _c2p I use is polygon "I" so matches circle probably don't need 100 sides the bigger the number the more accurate as you suggest.

 

Then use 

polygon Briscad is different than Acad

(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))

(command "erase" "WP" co-ord "" (entlast) "")

Posted
On 12/18/2020 at 2:41 PM, BIGAL said:

An alternative to _c2p I use is polygon "I" so matches circle probably don't need 100 sides the bigger the number the more accurate as you suggest.

 

Then use 

polygon Briscad is different than Acad

(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))

(command "erase" "WP" co-ord "" (entlast) "")

@BIGAL Why would you use a temp object when these points can be created with easy math?

Posted

You are correct, its the algorithm I use a lot as a library solution for say ssget "F" for a circle filter. 

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