Preview | SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MCMatthew Cempa01/05/2020
I believe that there is a bug with the IAnnotation:SetLeaderAttachmentPointAtIndex method.
Here is a simple macro that just gets the existing arrow points and sets their position to their current position. Thus there should be no change to the note leaders. This works fine for one leader but seems to only move the first leader no mater what index you put in. Included is a test part and drawing with notes. Select a note and run the macro to test. Has anyone run into this?
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Dim swSelMgr As SldWorks.SelectionMgr
Dim swAnnot As SldWorks.Annotation
Dim swNote As SldWorks.Note
Dim status As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Select Case swSelMgr.GetSelectedObjectType3(1, -1)
Case SwConst.swSelectType_e.swSelNOTES
Dim swDispData As SldWorks.DisplayData
Dim vArrowPts As Variant
Dim nLeaders As Integer
Dim i As Integer
'get the annotation
Set swNote = swSelMgr.GetSelectedObject6(1, -1)
Set swAnnot = swNote.GetAnnotation
nLeaders = swAnnot.GetLeaderCount
If swNote.IsAttached Then
'Save the arrow points information
Set swDispData = swAnnot.GetDisplayData
Dim vArrows() As Variant
ReDim vArrows(nLeaders - 1)
For i = 0 To UBound(vArrows)
vArrows(i) = swDispData.GetArrowHeadAtIndex(i)
Next i
're-position the arrows back to their original location
For i = 0 To UBound(vArrows)
vArrowPts = vArrows(i)
Debug.Print ("leader " & CStr(i) & ": " & Format(vArrowPts(0), "####.####") & ", " & _
Format(vArrowPts(1), "####.####") & ", " & _
Format(vArrowPts(2), "####.####"))
status = swAnnot.SetLeaderAttachmentPointAtIndex(CLng(i), vArrowPts(0), vArrowPts(1), vArrowPts(2))
Debug.Print ("Status: " & CStr(status))
swModel.EditRebuild3
Next i
End If
Case Else
'do nothing
End Select
End Sub