Here's a sample that I believe does what you want. It has an If statement so you can do it in one of two ways. The first is that it includes the work point into the view and adds the leader to it. The second is that it just uses the position of the work point to position the leader but the leader isn't actually attached to anything. Since you have a work point you probably want the first option so then if the work point moves the leader will also adjust.
I also made the assumption that you're working on an assembly drawing so the view is of an assembly. That's a more complex problem and that's what the sample demonstrates. If that's not true there's quite a bit of code that can be removed and simplified. Hopefully, this helps.
Private Sub CreateLeader()
Dim invApp As Inventor.Application = GetObject(, "Inventor.Application")
Dim drawDoc As DrawingDocument = invApp.ActiveDocument
' Find the view named "TestView" on the active sheet.
Dim sht As Sheet = drawDoc.ActiveSheet
For Each drawView As DrawingView In sht.DrawingViews
If drawView.Name = "TestView" Then
' Get the referenced assembly.
Dim tankAsm As AssemblyDocument = drawView.ReferencedDocumentDescriptor.ReferencedDocument
Dim tankAsmComp As AssemblyComponentDefinition = tankAsm.ComponentDefinition
' Get the occurrence of the tank in the assembly.
Dim tankOcc As ComponentOccurrence = tankAsmComp.Occurrences.ItemByName("Tank:1")
' Get the tank part.
Dim tankPartComp As PartComponentDefinition = tankOcc.Definition
' Get the work point named "TANKWP".
Dim tankWP As WorkPoint = tankPartComp.WorkPoints.Item("TANKWP")
' Get the value of the parameters.
Dim nameParam As Parameter = tankPartComp.Parameters.Item("TANKLEADER")
Dim volParam As Parameter = tankPartComp.Parameters.Item("WORKINGVOLUME")
Dim name As String = nameParam.Value
Dim vol As String = volParam.Value
Dim includeWP As Boolean = True
If includeWP Then
' Get the proxy of the work point because we need it in the context of the assembly.
Dim tankWPProxy As WorkPointProxy = Nothing
tankOcc.CreateGeometryProxy(tankWP, tankWPProxy)
' Include the work point.
Dim mark As Centermark = sht.Centermarks.AddByWorkFeature(tankWPProxy, drawView)
' Create the leader.
Dim pnts As ObjectCollection = invApp.TransientObjects.CreateObjectCollection
pnts.Add(invApp.TransientGeometry.CreatePoint2d(mark.Position.X + 3, mark.Position.Y + 2))
pnts.Add(sht.CreateGeometryIntent(mark))
sht.DrawingNotes.LeaderNotes.Add(pnts, name & "<Br/>" & vol)
Else
' Get the position of the work point. This is in the part space of the thank.
Dim wpModelPosition As Point = tankWP.Point
' Get the transform of the tank occurence. This defines the part to assembly transform.
Dim tankTrans As Matrix = tankOcc.Transformation
' Transform the point using this transform to go from part to assembly space.
wpModelPosition.TransformBy(tankTrans)
' Get this point in sheet space.
Dim wpViewPosition As Point2d = drawView.ModelToSheetSpace(wpModelPosition)
' Create the leader.
Dim pnts As ObjectCollection = invApp.TransientObjects.CreateObjectCollection
pnts.Add(invApp.TransientGeometry.CreatePoint2d(wpViewPosition.X + 3, wpViewPosition.Y + 2))
pnts.Add(wpViewPosition)
sht.DrawingNotes.LeaderNotes.Add(pnts, name & "<Br/>" & vol)
End If
End If
Next
End Sub
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com