Hi, I have no idea what you would need the dimension for, but you can try this:
There's actualy no need to find the sketch line, you just need the points.
Sub Main()
sPointOneX = 3
sPointOneY = 5
sPointTwoX = 25
sPointTwoY = 5
' Now we have to convert "mm" to "cm", because Inventor is measuring in "cm"
sPointOneX = sPointOneX * 0.1
sPointOneY = sPointOneY * 0.1
sPointTwoX = sPointTwoX * 0.1
sPointTwoY = sPointTwoY * 0.1
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
' Use this line to pick the first sketch in part
Dim oSketch As Sketch = oCD.Sketches.Item(1)
' Or use this line to pick the sketch by name
'Dim oSketch As Sketch = oCD.Sketches.Item("Sketch1")
Dim dCon As DimensionConstraint
Dim oPoint As Point2D
Dim oPara As Parameter
For Each dCon In oSketch.DimensionConstraints
Dim oPoints As ObjectCollection = dCon.AnchorPoints()
Dim TryNext As Boolean = False
Dim OurCon As Boolean = False
For Each oPoint In oPoints
If oPoint.X = sPointOneX And oPoint.Y = sPointOneY Then
If TryNext Then
OurCon = CheckSecond(oPoint)
Else
TryNext = True
End If
Else If oPoint.X = sPointTwoX And oPoint.Y = sPointTwoY Then
If TryNext Then
OurCon = CheckSecond(oPoint)
Else
TryNext = True
End If
End If
Next
If OurCon = True Then
oPara = dCon.Parameter
Exit For
End If
Next
If Not oPara Is Nothing Then
MsgBox(oPara.Name & vbLf & oPara.Value * 10) 'value multiplicated by 10 to convert units from "cm" to "mm"
End If
End Sub
Private sPointOneX As Double
Private sPointOneY As Double
Private sPointTwoX As Double
Private sPointTwoY As Double
Private Function CheckSecond(oPoint As Point2d) As Boolean
If oPoint.X = sPointOneX And oPoint.Y = sPointOneY Then
Return True
Else If oPoint.X = sPointTwoX And oPoint.Y = sPointTwoY
Return True
End If
Return False
End Function
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods