Following is my code to get the IndependentTag width by creating a new tag in the center of the reference. Needs some work but seems to work OK.
I was using this to left justify a selection of tags, however I cannot work out how to move the original tag from the TagHeadPosition to the selected point, less half the width using this function.
Public Shared Function GetIndependentTagWidth(ByVal objIndependentTag As IndependentTag) As Double Dim dblWidth As Double = 0 Try Dim objDocument As Document = objIndependentTag.Document Dim objActiveView As View = objDocument.ActiveView Using transGroup As New TransactionGroup(objDocument) transGroup.Start("Transaction Group") Using firstTrans As New Transaction(objDocument) Dim objReference As Reference = objIndependentTag.GetTaggedReference Dim objBoundingBoxXYZ As BoundingBoxXYZ = objDocument.GetElement(objReference.ElementId).BoundingBox(objActiveView) Dim boundingBoxMaxX As Double = objBoundingBoxXYZ.Max.X Dim boundingBoxMaxY As Double = objBoundingBoxXYZ.Max.Y Dim boundingBoxMinX As Double = objBoundingBoxXYZ.Min.X Dim boundingBoxMinY As Double = objBoundingBoxXYZ.Min.Y Dim elementXYZ As New XYZ(boundingBoxMaxX - ((boundingBoxMaxX - boundingBoxMinX) / 2), boundingBoxMaxY - ((boundingBoxMaxY - boundingBoxMinY) / 2), 0) firstTrans.Start("First Transaction") Dim objNewIndependentTag As IndependentTag = IndependentTag.Create( objDocument, objActiveView.Id, objIndependentTag.GetTaggedReference, False, TagMode.TM_ADDBY_CATEGORY, objIndependentTag.TagOrientation, elementXYZ) objBoundingBoxXYZ = objNewIndependentTag.BoundingBox(objActiveView) boundingBoxMaxX = objBoundingBoxXYZ.Max.X boundingBoxMinX = objBoundingBoxXYZ.Min.X dblWidth = boundingBoxMaxX - boundingBoxMinX objIndependentTag.HasLeader = False firstTrans.Commit() objBoundingBoxXYZ = objIndependentTag.BoundingBox(objActiveView) End Using transGroup.RollBack() End Using Catch ex As Exception Msgbox(ex.message) End Try Return dblWidth End Function
Kind Regards
David