Search This Blog

AutoLISP: Select All Points Inside Multiple Circles in AutoCAD


When working with dense survey data, site layouts, or coordinate grids in AutoCAD, manually selecting POINT entities inside circular boundaries can be slow and error-prone. While AutoCAD’s built-in WP (Window Polygon) selection works for single areas, it becomes tedious when you need to select points across dozens of circles at once.

Below is a free, lightweight AutoLISP routine (SelPtsInCircles) that lets you select multiple circles at once and automatically highlights every point inside them.

Features of This Routine

  • Multi-Circle Selection: Select individual circles, drag a selection window, or select all—the script automatically ignores non-circle objects.
  • 2D XY-Plane Filtering: Checks horizontal distance from each circle's center, meaning points at varying Z-elevations are still accurately captured.
  • Instant Grip Selection: Highlights matching points immediately so you can move, delete, copy, or change their layer right away.

Download or Copy the AutoLISP Code

Download the ready-to-use .lsp file directly, or click Copy Code to paste it into Notepad:

SelPtsInCircles.lsp
(defun c:SelPtsInCircles (/ cSS ptSS cList i ent obj center rad ptEnt ptCoords selSet inside)
  (vl-load-com)
  
  ;; Prompt user to select multiple circles
  (princ "\nSelect circles: ")
  (setq cSS (ssget '((0 . "CIRCLE"))))
  
  (if cSS
    (progn
      ;; Extract center (2D) and radius for every selected circle into a list
      (setq i 0)
      (repeat (sslength cSS)
        (setq ent (ssname cSS i))
        (setq obj (vlax-ename->vla-object ent))
        (setq center (vlax-get obj 'Center))
        (setq rad (vlax-get obj 'Radius))
        (setq cList (cons (list (list (car center) (cadr center)) rad) cList))
        (setq i (1+ i))
      )
      
      ;; Get all POINT entities in the current space
      (setq ptSS (ssget "_X" (list '(0 . "POINT") (cons 410 (getvar 'CTAB)))))
      
      (if ptSS
        (progn
          (setq selSet (ssadd))
          (setq i 0)
          
          ;; Check each point against the list of circles
          (repeat (sslength ptSS)
            (setq ptEnt (ssname ptSS i))
            (setq ptCoords (cdr (assoc 10 (entget ptEnt))))
            (setq ptCoords (list (car ptCoords) (cadr ptCoords)))
            
            ;; Test if point falls within any of the selected circles
            (setq inside nil)
            (foreach c cList
              (if (<= (distance (car c) ptCoords) (cadr c))
                (setq inside T)
              )
            )
            
            (if inside
              (ssadd ptEnt selSet)
            )
            (setq i (1+ i))
          )
          
          ;; Highlight and grip-select matching points
          (if (> (sslength selSet) 0)
            (progn
              (sssetfirst nil selSet)
              (princ (strcat "\n" (itoa (sslength selSet)) " point(s) selected inside " (itoa (sslength cSS)) " circle(s)."))
            )
            (princ "\nNo points found inside the selected circles.")
          )
        )
        (princ "\nNo points exist in the current layout/model space.")
      )
    )
    (princ "\nNo circles selected.")
  )
  (princ)
)

How to Load and Use It

  1. Save the File: Download SelPtsInCircles.lsp using the button above, or save the copied text as SelPtsInCircles.lsp (make sure the file extension is .lsp, not .lsp.txt).
  2. Load into AutoCAD: Open your drawing, type APPLOAD in the command line, and press Enter. Browse to your saved file and click Load.
  3. Run the Command: Type SelPtsInCircles in the command line and press Enter.
  4. Select Circles: Click or window-select the circles you want to check and press Enter. All points inside those circles will now be selected!
Tip: By default, points resting directly on a circle's edge are included. If you want to exclude boundary points, change <= to < on line 34.

No comments:

Post a Comment