I have attached a file with a drawing in it. Open the drawing and run the below code:
Sub showproblem()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDDoc As DrawingDocument
Set oDDoc = oApp.ActiveDocument
Dim oSheet As sheet
Set oSheet = oDDoc.ActiveSheet
Dim oDDims As DrawingDimensions
Set oDDims = oSheet.DrawingDimensions
Dim oDDim As DrawingDimension
Dim oLGDim As OrdinateDimension
oDDoc.SelectSet.Clear
Dim oOColl As ObjectCollection
Set oOColl = oApp.TransientObjects.CreateObjectCollection
For Each oDDim In oDDims
If TypeOf oDDim Is OrdinateDimension Then
Set oLGDim = oDDim
If oLGDim.DimensionType = kHorizontalDimensionType Then
Call oOColl.Add(oDDim)
End If
End If
Skipthis:
Next
Call oDDoc.SelectSet.SelectMultiple(oOColl)
Call showProblem2part
End Sub
Sub showProblem2part()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = oApp.ActiveDocument
' Determine how many dimensions are in the select set.
Dim oSelectSet As SelectSet
Set oSelectSet = oDrawDoc.SelectSet
Dim colDimensions As New Collection
Dim i As Long
For i = 1 To oSelectSet.count
If TypeOf oSelectSet.Item(i) Is DrawingDimension Then
' Add any dimensions to the collection. We need to save them
' in something besides the selection set because once we start
' manipulating them the select set will be cleared.
colDimensions.Add oSelectSet.Item(i)
End If
Next
For i = 1 To colDimensions.count
Dim oDimension As DrawingDimension
Set oDimension = colDimensions.Item(i)
If i = 1 Then
' Get the position of the first dimension text. This is
' the position the other dimensions will be aligned to.
Dim dPosition As Double
dPosition = oDimension.Text.Origin.x - 0.2
Else
If i = 2 Then
dPositionY = oDimension.Text.Origin.y
TopDim = oDimension.Text.Text
End If
' Change the position of the dimension.
Dim oPosition As Point2d
Set oPosition = oDimension.Text.Origin
oPosition.x = dPosition
'End If
'I don't understand why I have to run the below line twice, but it gets it closer to where it is supposed to be.
oDimension.Text.Origin = oPosition
oDimension.Text.Origin = oPosition
If TopDim = "used" Then GoTo SkipTopDim
TopDim = oDimension.Text.Text
If TopDim = findDim Then
oStr = " REF"
oDimension.Text.FormattedText = oStr
TopDim = "used"
End If
If TopDim = findDim2 Then
oStr = " REF"
oDimension.Text.FormattedText = oStr
TopDimValue = TopDim
TopDim = "used"
End If
SkipTopDim:
End If
Next
End Sub
if you set the oDimension.Text.Origin to a value that value should place the text at the exact location specified, but it doesn't. I have proven that by running the code twice in a row without the oPosition changing, or at least it shouldn't change, but it does.