@Anonymous wrote:
....
I work with structural foundation plans and need to insert certain blocks depending on what the area of each foundation is. For example, if the footing is 49 square feet, I center a 3-probe block on that foundation. Ultimately, I would love a lisp that would run through the closed polylines, find the centroid of each foundation, and then insert a block centered on the foundation. ....
If I may assume that your footings are all rectangular/square [as they always are in my experience], that looks a little more complicated than necessary [for instance, you don't need to create two temporary things that then need to be deleted when it's done -- there are simpler ways to find the midpoint of a rectangular Polyline than through a Region's centroid]. I would go about it something like this way [untested -- I didn't create various Blocks, etc.]:
(defun C:APF (/ ftgss ftgobj ftgarea); = Add Pile blocks to Footings
(prompt "\nTo add piling Blocks to foundations,")
(if (setq ftgss (ssget "_X" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
; closed 4-vertex Polylines only
(repeat (setq n (sslength ftgss)); then
(setq ftgobj (vlax-ename->vla-object (ssname ftgss (setq n (1- n)))))
(vla-getboundingbox ftgobj 'minpt 'maxpt)
(setq ftgarea (/ (vla-get-area ftgobj) 144)); area in square feet
(command "_.insert"
(cond ; Block name
((> ftgarea 64) "Your4PileBlockName"); anything over 8' square
((> ftgarea 36) "Your3PileBlockName"); over 6' square up to 8'
((> ftgarea 9) "Your2PileBlockName"); over 3' square up to 6'
("Your1PileBlockName"); anything no larger than 3' square
); cond
"_none" (mapcar '/ (mapcar '+ (vlax-safearray->list minpt) (vlax-safearray->list maxpt)) '(2 2 2)); midpoint
"" "" "" ; default scales of 1, rotation of 0
); command
); repeat [then]
(prompt "\nNo 4-sided closed Polyline(s) selected."); else
); if
(princ)
); defun
(vl-load-com)
Edit the bluish parts for your actual Block names, and the red parts for your actual break-point size categories [add more categories if needed]. It could also do other things, such as put them on a specified Layer, etc.
If they might not always be rectangular, something involving a centroid might be appropriate for finding the insertion point, but the (cond) function selecting the Block name based on the area would still apply.
I also assume you are using Architectural Units [a drawing unit = an inch], and that you always want the Blocks at scales of 1 and rotation of 0, and that they don't have Attributes -- adjust accordingly for any incorrect assumptions.
Kent Cooper, AIA