Follow key code → SwPt1.x → Is not the target demand coordinates
Ss = SwAnn.GetAttachedEntities2
Set SwPt1 = Ss(0)
SwPt1.X → Is not the target demand coordinates
SwPt1.Y → Is the target demand coordinates
Private Sub del20161224()
Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
Set SwApp = Application.SldWorks
Set SwModel = SwApp.ActiveDoc
Dim SwDraw As DrawingDoc
Set SwDraw = SwModel
Dim SwView As View
Set SwView = SwDraw.GetFirstView '
Set SwView = SwView.GetNextView
'Set SwView = SwView.GetNextView
oScale = 1 'SwView.ScaleDecimal
SwView.ScaleDecimal = oScale
SwDraw.ActivateView SwView.Name
Dim vPos, vPts(1)
vPts(0) = 0
vPts(1) = 0
SwView.SetXform vPts
Dim swSelMgr As SelectionMgr
Set swSelMgr = SwModel.SelectionManager
Dim SwDispDim As DisplayDimension, SwDim As Dimension, SwAnn As Annotation
Set SwDispDim = swSelMgr.GetSelectedObject5(1)
Set SwAnn = SwDispDim.GetAnnotation
Ss = SwAnn.GetAttachedEntities2
Dim SwPt1 As SketchPoint, SwPt2 As SketchPoint
Set SwPt1 = Ss(0)
Debug.Print SwPt1.X, SwPt1.Y
Stop
Dim DimPt, SwSketchLine As SketchLine, SwSktSeg As SketchSegment
Set SwAnn = SwDispDim.GetAnnotation
DimPt = SwAnn.GetPosition
'Set SwSktSeg = SwModel.CreateLine2(vPts(0), vPts(0), 0, DimPt(0) / oScale, DimPt(1) / oScale, 0)
Set SwSktSeg = SwModel.CreateLine2(SwPt1.X, SwPt1.Y, 0, DimPt(0) / oScale, DimPt(1) / oScale, 0)
SwSktSeg.Layer = "尺寸线"
SwView.UseSheetScale = True
SwModel.ForceRebuild3 True
''
Stop
Stop
End Sub
SolidworksApi macros