I had so many things going on with work and the forums too, I lost track and didn't get back here very soon. I created something (fairly complex) you may be able to use to help streamline this process a bit better. It does the whole process from scratch. It first allows you to select a model edge (DrawingCurveSegment) in a drawing view (the part you want to attach one of these custom leader note's to. Then it inspects the selected DrawingCurveSegment object to retrieve all needed info about it for the leader note. I'm attempting to make it work for either a view of a single part document, or a view of an assembly document, so it will be more flexible/useful, but I'm sure it can use some more refinement and additional error handling to suit various needs/scenarios.
This example pulls the model's 'Description' iProperty value to use as the first line of text in the note, then it pulls the model's 'Part Number' iProperty value to use in the second line of the note, then gets the Qty value (one way or another) to use in the third line of the note. But you can change which properties it's using if you want. You may also need to check if the property has a value (not empty) before attempting to put its value into the note. There is a lot in this rule, and I'm assuming a lot, so read through it first. When creating a leader note, you need to supply a point location for where you want to put it, so I just used the upper right corner of the drawing view as the outer point to place the text part of it. This can also be changed however you want it. Then I put a little message at the end of the process that pops up asking if you want to repeat it, just to make the whole thing way more handy. 🙂
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oDCurve As DrawingCurveSegment
RepeatProcess :
oDCurve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a DrawingCurveSegment.")
If oDCurve Is Nothing Then
MsgBox("Nothing was selected. Exiting.")
Exit Sub
End If
Dim oView As DrawingView = oDCurve.Parent.Parent
'check view doc's type first, then use that to determine edge type (Edge or EdgeProxy), and other stuff
Dim oDTProps As PropertySet
Dim oQty As Integer
If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oViewDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oEdge As EdgeProxy = oDCurve.Parent.ModelGeometry
Dim oBody As SurfaceBodyProxy = oEdge.Parent
Dim oOcc As ComponentOccurrence = oBody.Parent
Dim oOccDoc As Document = oOcc.Definition.Document
oDTProps = oOccDoc.PropertySets.Item("Design Tracking Properties")
'now set value of oQty
'may have to inspect & consider things like design view representation and/or Level of Detail (LOD) of the view be accurate
Dim oBOMViews As BOMViews = oViewDoc.ComponentDefinition.BOM.BOMViews
For Each oBOMView As BOMView In oBOMViews
If oBOMView.ViewType <> BOMViewTypeEnum.kModelDataBOMViewType Then Continue For
For Each oRow As BOMRow In oBOMView.BOMRows
If oRow.ComponentDefinitions.Item(1) Is oOcc.Definition Then
oQty = oRow.ItemQuantity
End If
Next
Next
ElseIf oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oViewDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oEdge As Edge = oDCurve.Parent.ModelGeometry
Dim oBody As SurfaceBody = oEdge.Parent
Dim oPDef As PartComponentDefinition = oBody.Parent
Dim oPDoc As PartDocument = oPDef.Document
oDTProps = oPDoc.PropertySets.Item("Design Tracking Properties")
oQty = 1
End If
Dim oDesc As String = oDTProps.Item("Description").Value
Dim oPN As String = oDTProps.Item("Part Number").Value
'create a new LeaderNote attached to the selected geometry
Dim oGeomIntent As GeometryIntent = oSheet.CreateGeometryIntent(oDCurve.Parent, .5)
Dim oPt As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((oView.Left + oView.Width), oView.Top)
Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oLeaderPoints.Add(oPt)
oLeaderPoints.Add(oGeomIntent)
Dim oFText As String = oDesc & "<Br/>" & "Part No. " & oPN & "<Br/>" & "Qty. " & oQty
Dim oLNote As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, oFText)
oRepeat = MsgBox("Create another custom leader?", vbYesNo + vbQuestion, "REPEAT?")
If oRepeat = vbYes Then GoTo RepeatProcess
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)