@Kent1Cooper wrote:
.... for Polylines or Splines with certain kinds of convolutions in their shapes, Offsetting even outward can result in more than one new Polyline. ...
Here's a thought: When that happens, if such a Polyline is Offset outboard, there will be one resulting Polyline that is larger than the selected boundary, even if there may also be some other smaller one(s). So what if, after Offsetting, the routine finds all objects newer than the last one before starting, no matter how many there are [i.e. all results from the Offset], and compares the area of the largest of those to the boundary? If the largest of them is smaller than the boundary, then the Block must be inside the boundary. If that's a sufficient test, it takes a heck of a lot less code than making ray-casting (etc.) routines foolproof:
(defun C:BIB ; = Blocks Inside Boundary
(/ bndry reflen blks n new elast blk)
(setq
bndry (car (entsel "\nBoundary object: "))
reflen (vla-get-area (vlax-ename->vla-object bndry))
blks (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab))))
insiders (ssadd); initially empty
); setq
(repeat (setq n (sslength blks))
(setq new (ssadd) elast (entlast)); reset for each -- initially empty set
(command "_.offset" "_through" bndry
"_none" (cdr (assoc 10 (entget (setq blk (ssname blks (setq n (1- n)))))))
""
); command
(while (setq elast (entnext elast)) (ssadd elast new)); however many result
(if ; are ALL of the objects resulting from Offset smaller than the boundary?
(<
(apply 'max ; compare only the largest resulting object
(mapcar
'(lambda (x) (vla-get-area (vlax-ename->vla-object x)))
(mapcar 'cadr (ssnamex new)); list of result-object entity names
); mapcar
); 'max
reflen
); <
(ssadd blk insiders); then -- put it in selection
); if
(command "_.u"); Undo Offset [however many it made]
); repeat
(prompt (strcat "\n" (itoa (sslength insiders)) " Block(s) found inside & put in 'insiders' selection set."))
(princ)
); defun
HOWEVER, I find that Splines of not-even-all-that-convoluted shapes can sometimes result in an outboard path that isn't one Spline, but is in segments. So the above wouldn't be completely reliable with Spline boundaries. But if you use it only on Polylines [Circles and Ellipses work, too], it may be viable for you.
Again, it only identifies the Blocks with insertion points inside -- process further in ways already offered. And it would still have a problem if a Block was at a central interior point that would not give a result [see Post 31], if that's a possibility, but that one, at least, could perhaps be accounted for with some (vl-catch-all...) code.
[If you use it on an Arc or a partial Ellipse, I believe it will "see" all Blocks whose insertion points would be inside the equivalent closed extension of the boundary -- Circle or full Ellipse -- whether or not they're inside the shape of the boundary if closed across with a straight line.]
Kent Cooper, AIA