Extract Size of Blocked Entity

Extract Size of Blocked Entity

aliff_ahtenk
Enthusiast Enthusiast
261 Views
2 Replies
Message 1 of 3

Extract Size of Blocked Entity

aliff_ahtenk
Enthusiast
Enthusiast

Hai Guys.. Long time no see.. I am quite busy for a long time thou..

 

Anyways, is there a way to extract x,y,z of a blocked entity? in which, in side of the blocked entity will have another block, lines, polyline, point, solid, hatches mostly. combination of this become a product or part..

 

As example a product is a centrifugal fan, so the blocked entity will consist of the frame, fan shell and motor. i am thinking of the lips should detect the block like a simple solid box to get the x,y,z and show result of the fan dimension, like X by Y by Z.

I hope this explanation is clear, i don't know how to explain well.. sorry guys..

0 Likes
262 Views
2 Replies
Replies (2)
Message 2 of 3

marko_ribar
Advisor
Advisor

Try to use (vla-getboundingbox) method on your block(s)...

If you want XYZ of more than 1 block, then you can create temp block of all of them and also try (vla-getboundingbox)... Only thing you should avoid is that you select spline entity within blocks - this is known bug of AutoCAD - in BricsCAD this issue was fixed...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant

Here's what I use:

 

(defun C:BB (/ minpt maxpt); Bounding Box of selected object
  (vla-getboundingbox (vlax-ename->vla-object (car (entsel))) 'minpt 'maxpt)
  (setq
    box (list (vlax-safearray->list minpt) (vlax-safearray->list maxpt))
    delta (mapcar '- (cadr box) (car box))
  ); setq
  (prompt
    (strcat
      "\nBounding Box [in 'box' variable]: " (vl-princ-to-string box) ";"
      "\nExtents [in 'delta' variable]: X direction " (rtos (car delta))
      "; Y direction " (rtos (cadr delta))
      "; Z direction " (rtos (caddr delta)) "."
    ); strcat
  ); prompt
  (prin1)
)

 

And if you don't want to define the parts together into a Block first, to be a single object for the BB command, you can use this BBM command to get their collective extents in multiple-object selection:

 

;|
BoundingBoxMult.lsp [command name: BBM]
To find the collective Bounding Box around Multiple objects. Finds overall extents
of all object(s) selected, and reports corners and size in X, Y, & Z directions.
Kent Cooper, 12 June 2024
|;
(defun C:BBM (/ ss minpt maxpt eLL eUR LL UR); = Bounding Box, Multiple objects
  (prompt "\nFor the collective extents of Multiple objects,")
  (if (setq ss (ssget))
    (progn ; then
      (repeat (setq n (sslength ss))
        (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 'minpt 'maxpt)
        (setq
          eLL (vlax-safearray->list minpt)
          eUR (vlax-safearray->list maxpt)
          LL (if LL (mapcar 'min eLL LL) eLL)
          UR (if UR (mapcar 'max eUR UR) eUR)
        ); setq
      ); repeat
      (setq
        box (list LL UR)
        delta (mapcar '- UR LL)
      ); setq
      (prompt
        (strcat
          "\nBounding Box [in 'box' variable]: " (vl-princ-to-string box) ";"
          "\nExtents [in 'delta' variable]: X direction " (rtos (car delta))
          "; Y direction " (rtos (cadr delta))
          "; Z direction " (rtos (caddr delta)) "."
        ); strcat
      ); prompt
    ); progn
    (prompt "\nNothing selected."); else
  ); if
  (prin1)
); defun
(vl-load-com)
(prompt "\nType BBM to get the collective Bounding Box around Multiple objects.")

 

Both leave the corners of the extents in the 'box' variable and the size of the extents in the 'delta' variable [not localized], to use as you may wish.

Kent Cooper, AIA
0 Likes