Hello
I want to add a note via a macro related to the property of the component to which it is attached in a SolidWorks drawing.
I tried using the SolidWorks registration method but the generated code doesn't work for me. This is because it selects the part based on its coordinates and if I want to apply this macro to another drawing where the part is, it doesn't work if the part isn't placed the same way on the sheet.
Here is the code generated by SolidWorks:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.418950851731392, 0.261697604464967, -499.977072134691, False, 0, Nothing, 0)
Dim myNote As Object
Dim myAnnotation As Object
Dim myTextFormat As Object
Set myNote = Part.InsertNote("$PRPMODEL:""Landmark""")
If Not myNote Is Nothing Then
myNote.LockPosition = False
myNote.Angle = 0
boolstatus = myNote.SetBalloon(0, 0)
Set myAnnotation = myNote.GetAnnotation()
If not myAnnotation is nothing then
longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swSTRAIGHT, 0, True, False, False, False)
boolstatus = myAnnotation.SetPosition(0.304559076486096, 0.311886588479215, 0)
boolstatus = myAnnotation.SetTextFormat(0, True, myTextFormat)
End If
End If
Part.ClearSelection2 True
Part.WindowRedraw
End Sub
I tried replacing boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.418950851731392, 0.261697604464967, -499.977072134691, False, 0, Nothing, 0)
by
boolstatus = Part.Extension.SelectByID2("Part2-1", "COMPONENT", 0.418950851731392, 0.261697604464967, -499.977072134691, False, 0, Nothing, 0)
But it doesn't work.
Does anyone know of a solution?
Thank you