I hope this comes in handy for someone in the future.
Analyzing and displaying kOrdinateDimension line points:
Sub Main()
Dim drawingDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim activeSheet As Sheet = drawingDoc.ActiveSheet
Dim transientGeom As TransientGeometry = ThisApplication.TransientGeometry
' Locate the first ordinate dimension on the active sheet
Dim dimension As DrawingDimension = Nothing
For Each dimen As DrawingDimension In activeSheet.DrawingDimensions
If dimen.Type = 117484800 Then ' kOrdinateDimensionObject
dimension = dimen
Exit For
End If
Next
If dimension Is Nothing Then
MsgBox("No ordinate dimension found on the active sheet.", vbExclamation, "Error")
Exit Sub
End If
' Create a temporary sketch to display markers and bounding box
Dim sketch As DrawingSketch = activeSheet.Sketches.Add()
sketch.Edit()
Dim markerRadius As Double = 0.1
Dim dimLine As Object = dimension.DimensionLine
Dim pointCount As Integer = dimLine.PointCount
Dim textRange As Box2d = dimension.Text.RangeBox
' Declare points once at the top
Dim startPoint As Point2d = dimLine.PointAtIndex(1)
Dim endPoint As Point2d = dimLine.PointAtIndex(pointCount)
Dim jogPointOne As Point2d = dimension.JogPointOne
Dim jogPointTwo As Point2d = dimension.JogPointTwo
Dim textOrigin As Point2d = dimension.Text.Origin
' Calculate and draw the bounding box encompassing the entire dimension line and text at the start
If Not textRange Is Nothing Then
' Initialize min and max coordinates with start point
Dim minX As Double = startPoint.X
Dim minY As Double = startPoint.Y
Dim maxX As Double = startPoint.X
Dim maxY As Double = startPoint.Y
' Update bounds with end point
If endPoint.X < minX Then minX = endPoint.X
If endPoint.Y < minY Then minY = endPoint.Y
If endPoint.X > maxX Then maxX = endPoint.X
If endPoint.Y > maxY Then maxY = endPoint.Y
' Include JogPointOne if available
If Not jogPointOne Is Nothing Then
If jogPointOne.X < minX Then minX = jogPointOne.X
If jogPointOne.Y < minY Then minY = jogPointOne.Y
If jogPointOne.X > maxX Then maxX = jogPointOne.X
If jogPointOne.Y > maxY Then maxY = jogPointOne.Y
End If
' Include JogPointTwo if available
If Not jogPointTwo Is Nothing Then
If jogPointTwo.X < minX Then minX = jogPointTwo.X
If jogPointTwo.Y < minY Then minY = jogPointTwo.Y
If jogPointTwo.X > maxX Then maxX = jogPointTwo.X
If jogPointTwo.Y > maxY Then maxY = jogPointTwo.Y
End If
' Include text bounding box (Text.Origin is within RangeBox)
If textRange.MinPoint.X < minX Then minX = textRange.MinPoint.X
If textRange.MinPoint.Y < minY Then minY = textRange.MinPoint.Y
If textRange.MaxPoint.X > maxX Then maxX = textRange.MaxPoint.X
If textRange.MaxPoint.Y > maxY Then maxY = textRange.MaxPoint.Y
' Add padding to the bounding box
Dim padding As Double = 0.2 ' Padding in centimeters
minX = minX - padding
minY = minY - padding
maxX = maxX + padding
maxY = maxY + padding
' Define the corners of the padded bounding box
Dim bottomLeft As Point2d = transientGeom.CreatePoint2d(minX, minY)
Dim topRight As Point2d = transientGeom.CreatePoint2d(maxX, maxY)
' Draw the dashed rectangle representing the bounding box
Dim boundingBoxEntities As SketchEntitiesEnumerator = sketch.SketchLines.AddAsTwoPointRectangle(bottomLeft, topRight)
For Each line As SketchLine In boundingBoxEntities
Line.LineType = kDashedLineType ' Set to dashed line (65793)
Next
Else
MsgBox("Text.RangeBox is unavailable; bounding box cannot be drawn.", vbExclamation, "Error")
End If
' Mark all points using the helper subroutine
MarkPoint(sketch, startPoint, "Start point of the dimension line marked (DimensionLine.PointAtIndex(1)).")
If Not jogPointOne Is Nothing Then MarkPoint(sketch, jogPointOne, "JogPointOne of the ordinate dimension marked.")
If Not jogPointTwo Is Nothing Then MarkPoint(sketch, jogPointTwo, "JogPointTwo of the ordinate dimension marked.")
MarkPoint(sketch, endPoint, "End point of the dimension line marked (DimensionLine.PointAtIndex(PointCount)).")
If Not textOrigin Is Nothing Then MarkPoint(sketch, textOrigin, "Text.Origin of the ordinate dimension marked.")
' Finalize the sketch (bounding box and markers are deleted with the sketch)
sketch.ExitEdit()
sketch.Delete()
MsgBox("Analysis of available objects completed.", vbInformation, "Done")
End Sub
' Helper subroutine to mark a point with a red circle
Sub MarkPoint(sketch As DrawingSketch, point As Point2d, message As String)
Dim markerRadius As Double = 0.1
Dim circle As SketchCircle = sketch.SketchCircles.AddByCenterRadius(point, markerRadius)
circle.OverrideColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) ' Red color
MsgBox(message, vbInformation, "Object Type")
sketch.SketchEntities.Item(sketch.SketchEntities.Count).Delete()
End Sub
INV 2025.3