TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Biscuits on July 12, 2017, 09:01:06 AM

Title: Selection set
Post by: Biscuits on July 12, 2017, 09:01:06 AM
How would I go about creating a selection set that would include a circle (if it exists) and anything inside it and return the diameter as a variable to be used later in a routine? This has me stumped.
Thanks for any ideas.
Title: Re: Selection set
Post by: ronjonp on July 12, 2017, 09:10:52 AM
First thing that comes to mind is pick the circle, trace it with points then use ssget "WP".
Title: Re: Selection set
Post by: PKENEWELL on July 26, 2017, 03:19:08 PM
Here's and oldie from my CAD library. Change the line with (setq ss (ssget "CP" ptlst)) to "WP" to select all inside only. You can also increase or decrease the accuracy by changing the value of the "inc" variable.
Code - Auto/Visual Lisp: [Select]
  1. ;; ----- (pjk-ssget-cir [Entity Name]) ----------------
  2. ;; This function selects all the objects within or crossing a
  3. ;; circle with the [Entity Name] given. Returns the resulting
  4. ;; selection set.
  5. (defun pjk-ssget-cir (enam / cnt cen elst ful inc pt ptlst rad ss)
  6.         (if enam
  7.                 (progn
  8.                         (setq elst (entget enam) ptlst nil
  9.                                 cen (trans (cdr (assoc 10 elst)) enam 0)
  10.                                 rad (cdr (assoc 40 elst))
  11.                                 inc 1.0
  12.                                 ful (/ 360.0 inc)
  13.                                 cnt 0.0
  14.                         )
  15.                         ;; Created a Point list for 360 points on curcumference of
  16.                         ;; the circle to use with "Crossing Polygon" selection.
  17.                         (while (< cnt ful)
  18.                                 (setq pt (polar cen (pjk-dtr cnt) rad)
  19.                                         ptlst (cons pt ptlst)
  20.                                         cnt (+ inc cnt)
  21.                                 )
  22.                         )
  23.                         (reverse ptlst)
  24.                         ;; Delete the circle.
  25.                         (entdel enam)
  26.                         ;; Select by Crossing polygon.
  27.                         (setq ss (ssget "CP" ptlst))
  28.                         ;; Undelete the Circle.
  29.                         (entdel enam)
  30.                         ss
  31.                 )
  32.                 nil
  33.         )
  34. ) ;; End Function (pjk-ssget-cir)
  35.