Author Topic: Selecting and fltering inside an area  (Read 864 times)

0 Members and 1 Guest are viewing this topic.

TimeGuardian

  • Mosquito
  • Posts: 1
Selecting and fltering inside an area
« on: March 08, 2022, 09:19:40 AM »
My problem is simple, i have many rectangles of the same size with objects inside them and for each rectangle i would like to select specific objects inside it and count. In the example image below, the objects to be selected are the red circles.



However there is the issue when the object is in multiple rectangles but i only want to count it once. In the example image below the point used to decide in which rectangle the object is, is the center of the circle.



If i only select whats completely inside the rectangle i wont be able to count the objects inside multiple rectangles but if i select everything even if its only partially inside i will count the same object multiple times.

kirby

  • Newt
  • Posts: 132
Re: Selecting and fltering inside an area
« Reply #1 on: March 08, 2022, 05:38:13 PM »
You could use the centroid of the various shapes to test if inside the boundary.   Centroid is simple calc for circles obtuse polygons.    More difficult for polylines (convert to Region then use vl-get-centroid, or use old school MassProp, or solve by geometry).  If your shapes are blocks whose insertion point is at the centroid, then the problem is really simply.

However, will still need to resolve how to handle the condition where a centroid falls exactly on a boundary.

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Selecting and fltering inside an area
« Reply #2 on: March 09, 2022, 04:20:39 AM »
What does the method  (ssget "WP" listofco-ords return

Code: [Select]
(setq plent (entsel "\nPick rectang"))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(sslength (ssget "WP" co-ord (list (cons 0 "CIRCLE"))))
3

A man who never made a mistake never made anything

mhupp

  • Bull Frog
  • Posts: 250
Re: Selecting and fltering inside an area
« Reply #3 on: March 11, 2022, 12:08:11 AM »
If those circles are blocks & its insertion point is in the center. this will do what you want.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ SS1 blkname SS blklst rec LL UR)
  2.   (setq SS1 (ssadd))
  3.   (setq blkname (cdr (assoc 2 (entget (car (entsel "\nPick Block"))))))
  4.   (if (setq SS (ssget "_X" (list '(0 . "Insert") (cons 2 blkname))))
  5.     (setq blklst (mapcar '(lambda (x) (list (cdr (assoc 10 (entget x))) x)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))))
  6.   )
  7.   (setq rec (vlax-ename->vla-object (car (entsel "\nPick Rectangle"))))
  8.   (vla-getboundingbox rec 'minpt 'maxpt)
  9.   (setq LL (vlax-safearray->list minpt)
  10.         UR (vlax-safearray->list maxpt)
  11.   )  
  12.   (foreach blk blklst
  13.     (if (and (< (car LL) (caar blk) (car UR)) (< (cadr LL) (cadar blk) (cadr UR)))
  14.       (ssadd (cadr blk) SS1)
  15.     )
  16.   )
  17.   ;or whatever else you want to do with the selection
  18.   (prompt (strcat "\n" (itoa (sslength ss1)) " \"" blkname "\" Blocks Inside Selected Rectangle"))
  19.   (sssetfirst nil ss1)
  20.   (princ)
  21. )

If they are just circles just delete line 4 and replace line 5 & 19 with
Code - Auto/Visual Lisp: [Select]
  1. (if (setq SS (ssget "_X" '((0 . "Circle"))))
  2. (prompt (strcat "\n" (itoa (sslength ss1)) " Circles Inside Selected Rectangle"))