- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In order to find duplicate blocks exported from revit, I am trying to compare two blocks using their boundary boxes to determine whether they are identical, mirrored across x or y axis or neither. I have the following script.
(defun c:CompareBlocks ()
(vl-load-com)
(defun GetBoundingBox (entity)
(vla-getboundingbox entity 'minPoint 'maxPoint)
(list (vlax-safearray->list minPoint) (vlax-safearray->list maxPoint))
)
(defun CombineBoundingBoxes (bbox1 bbox2)
(list
(mapcar 'min (car bbox1) (car bbox2))
(mapcar 'max (cadr bbox1) (cadr bbox2))
)
)
(defun GetTotalBoundingBox (block)
(setq blockObj (vlax-ename->vla-object block))
(setq totalBBox nil)
(setq blockDef (vla-item (vla-get-blocks (vla-get-document blockObj)) (vla-get-effectivename blockObj)))
(vlax-for entity blockDef
(setq entityBBox (GetBoundingBox entity))
(if totalBBox
(setq totalBBox (CombineBoundingBoxes totalBBox entityBBox))
(setq totalBBox entityBBox)
)
)
totalBBox
)
(defun CompareBoundingBoxes (bbox1 bbox2)
;; Split the bounding box into min and max points
(setq min1x (car (car bbox1)))
(setq min1y (cadr (car bbox1)))
(setq max1x (car (cadr bbox1)))
(setq max1y (cadr (cadr bbox1)))
(setq min2x (car (car bbox2)))
(setq min2y (cadr (car bbox2)))
(setq max2x (car (cadr bbox2)))
(setq max2y (cadr (cadr bbox2)))
;; Compare the bounding boxes
(setq identical (equal bbox1 bbox2))
(setq mirrored-x (and (equal min1x min2x) (equal max1x max2x)
(equal min1y -max2y) (equal max1y -min2y)))
(setq mirrored-y (and (equal min1x -max2x) (equal max1x -min2x)
(equal min1y min2y) (equal max1y max2y)))
(cond
(identical (princ "\nThe blocks are identical."))
(mirrored-x (princ "\nThe blocks are mirrored along the x-axis."))
(mirrored-y (princ "\nThe blocks are mirrored along the y-axis."))
(t (princ "\nThe blocks are not identical.")))
)
(setq block1 (car (entsel "\nSelect first block: ")))
(setq block2 (car (entsel "\nSelect second block: ")))
(if (and block1 block2)
(progn
(setq bbox1 (GetTotalBoundingBox block1))
(setq bbox2 (GetTotalBoundingBox block2))
(princ (strcat "\nBounding box of the first block: " (vl-princ-to-string bbox1)))
(princ (strcat "\nBounding box of the second block: " (vl-princ-to-string bbox2)))
(CompareBoundingBoxes bbox1 bbox2)
)
(princ "\nSelection error.")
)
(princ)
)
The example:
bbox1 = ((-25.3115, -40.2049), (65.6885, 43.7951))
bbox2 = ((-25.3115, -43.7951), (65.6885, 40.2049))
evaluates to "not identical" and I can't figure out why mirrored-x is evaluating to nil.
(setq mirrored-x (and (equal min1x min2x) (equal max1x max2x)
(equal min1y -max2y) (equal max1y -min2y)))
min1y (-40.2049) should be equal to -max2y(-40.2049), and the same should be true of max1y(43.7951) and -min2y(43.7951).
Solved! Go to Solution.
Link copied