I want to dimension the centerline in drawing using API, but it doesn't give the correct result, may I know how to do it correctly? Below are my sample code and the example files:
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc
swModel.ClearSelection2 True
Dim swSelMgr As SelectionMgr
'Dim swSelData As SelectData
Set swSelMgr = swModel.SelectionManager
swModel.Extension.SelectByID2 "Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0
Dim swView As View
Set swView = swSelMgr.GetSelectedObject6(1, -1)
'Set swSelData = swSelMgr.CreateSelectData
'swSelData.View = swView
Dim Centrelines As Variant
Dim Centreline As Variant
Centrelines = swView.GetCenterLines
Dim swCentreline As Centerline
Dim swAnn As Annotation
swModel.ClearSelection2 True
For Each Centreline In Centrelines
Set swCentreline = Centreline
Set swAnn = swCentreline.GetAnnotation
swAnn.Select3 True, Nothing ' doesn't work with selection data
Next Centreline
' add dimension
swModel.AddDimension2 0.2, 0.25, 0
End Sub