This was a lot harder than it should have been. For some reason I can't make a block attribute definition and store it into a variable and find the bounding box on that variable. However, if I create the block, go in block editor and get the object from the attribute definition, the GetBoundingBox method will work. I looked into it, and the handle produced from creating the attdef is not the same as the one where I select the attdef. I don't know what is going on there, but I have found a work around.
; Name: J. Overkamp
; Date: 03/21/2020
; Parameters:
; textObject - VLA-OBJECT attribute/attributeReference
; Return:
; bounding box
(defun JO:textboxODBX (textObject / *error* JO:findFontFile acadObject activeDocument document objectName
textHeight textString textRotation textWidth textObliqueAngle textStyleName textAlignment
textHorizontalAlignment textVerticalAlignment documentTextStyles activeDocumentTextStyles documentTextStyle
i newTextStyle newTextStyleName complete boundingBox textInsertionPoint
)
(defun *error* (msg / )
(acet-ui-progress-done)
(if (= 'VLA-OBJECT (type newTextStyle))
(vla-delete newTextStyle)
)
(princ "Error: ")
(princ msg)
(princ)
)
(defun JO:findFontFile (font / filePath path files)
(setq filePath (findfile font))
(if filePath
(progn
filePath
)
(progn
(setq path (strcat (getenv "windir") "\\Fonts\\"))
(setq files (vl-directory-files path "*"))
(if (member font files)
(strcat path font)
)
)
)
)
(if
(and
(setq objectName (vla-get-objectName textObject))
(wcmatch objectName "AcDbAttributeReference,AcDbAttributeDefinition,AcDbAttribute")
)
(progn
(setq acadObject (vlax-get-acad-object))
(setq activeDocument (vla-get-activeDocument acadObject))
(setq document (vla-get-document textObject))
(setq textHeight (vla-get-Height textObject))
(setq textString (vla-get-TextString textObject))
(setq textRotation (vla-get-Rotation textObject))
(setq textWidth (vla-get-ScaleFactor textObject))
(setq textObliqueAngle (vla-get-ObliqueAngle textObject))
(setq textStyleName (vla-get-StyleName textObject))
(setq textAlignment (vla-get-alignment textObject))
(cond
((= textAlignment acAlignmentLeft)
(setq textHorizontalAlignment 0)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentCenter)
(setq textHorizontalAlignment 1)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentRight)
(setq textHorizontalAlignment 2)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentAligned)
(setq textHorizontalAlignment 3)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentMiddle)
(setq textHorizontalAlignment 4)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentFit)
(setq textHorizontalAlignment 5)
(setq textVerticalAlignment 0)
)
((= textAlignment acAlignmentTopLeft)
(setq textHorizontalAlignment 0)
(setq textVerticalAlignment 3)
)
((= textAlignment acAlignmentTopCenter)
(setq textHorizontalAlignment 1)
(setq textVerticalAlignment 3)
)
((= textAlignment acAlignmentTopRight)
(setq textHorizontalAlignment 2)
(setq textVerticalAlignment 3)
)
((= textAlignment acAlignmentMiddleLeft)
(setq textHorizontalAlignment 0)
(setq textVerticalAlignment 2)
)
((= textAlignment acAlignmentMiddleCenter)
(setq textHorizontalAlignment 1)
(setq textVerticalAlignment 2)
)
((= textAlignment acAlignmentMiddleRight)
(setq textHorizontalAlignment 2)
(setq textVerticalAlignment 2)
)
((= textAlignment acAlignmentBottomLeft)
(setq textHorizontalAlignment 0)
(setq textVerticalAlignment 1)
)
((= textAlignment acAlignmentBottomCenter)
(setq textHorizontalAlignment 1)
(setq textVerticalAlignment 1)
)
((= textAlignment acAlignmentBottomRight)
(setq textHorizontalAlignment 2)
(setq textVerticalAlignment 1)
)
)
(setq documentTextStyles (vla-get-TextStyles document))
(setq activeDocumentTextStyles (vla-get-TextStyles activeDocument))
(setq documentTextStyle (vla-Item documentTextStyles textStyleName))
(setq i 0)
(while
(and
(setq i (1+ i))
(not complete)
)
(setq newTextStyleName (strcat textStyleName (itoa i)))
(if
(and
(vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list activeDocumentTextStyles newTextStyleName)))
(vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list documentTextStyles newTextStyleName)))
)
(progn
(setq newTextStyle (vla-add activeDocumentTextStyles newTextStyleName))
(setq complete T)
)
)
)
(setq bigFontFile
(JO:findFontFile (vla-get-BigFontFile documentTextStyle))
)
(if bigFontFile
(vla-put-BigFontFile newTextStyle bigFontFile)
)
(setq fontFile
(JO:findFontFile (vla-get-FontFile documentTextStyle))
)
(if fontFile
(vla-put-FontFile newTextStyle fontFile)
)
(vla-put-Height newTextStyle (vla-get-Height documentTextStyle))
(vla-put-LastHeight newTextStyle (vla-get-LastHeight documentTextStyle))
(vla-put-ObliqueAngle newTextStyle (vla-get-ObliqueAngle documentTextStyle))
(vla-put-TextGenerationFlag newTextStyle (vla-get-TextGenerationFlag documentTextStyle))
(vla-put-Width newTextStyle (vla-get-Width documentTextStyle))
(cond
((wcmatch objectName "AcDbAttributeReference,AcDbAttributeDefinition,AcDbAttribute")
(setq boundingBox
(textbox
(list
(cons 40 textHeight)
(cons 1 textString)
(cons 50 textRotation)
(cons 41 textWidth)
(cons 51 textObliqueAngle)
(cons 7 newTextStyleName)
(cons 72 textHorizontalAlignment)
(cons 74 textVerticalAlignment)
)
)
)
(if (not boundingBox)
(progn
(setq textInsertionPoint (vla-get-insertionPoint textObject))
(setq boundingBox (list textInsertionPoint textInsertionPoint))
)
)
)
)
(vla-delete newTextStyle)
)
)
boundingBox
)