Create Leader Note with the Value of User or Model Parameter or Document Property

By Barbara Han

Issue
We are looking for the way of linking the user or model parameter in part file to the leader note text in drawing through API. We have done it manually but we wanted to do that through API. The following picture illustrates the result what we want. The highlighted in red is the parameter to be used.

115

Solution
The LeaderNote.FormatedText property is writable and supports document property tag and parameter tag.
 
First of all, find style override string for the LeaderNote.FormatedText property, for example: (the ComponentIdentifier string is the part file path, which must be different in each case.) 
<StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HoleQuantity’ Precision=’0′>8</Parameter></StyleOverride><StyleOverride Font=’Arial’> HOLES ON DIA </StyleOverride><StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HolePCD’ Precision=’0′>35</Parameter></StyleOverride><StyleOverride Font=’Arial’>±0.1 </StyleOverride><Br/><StyleOverride Font=’Arial’>WITH </StyleOverride><StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HoleQuantity’ Precision=’0′>8</Parameter></StyleOverride><StyleOverride Font=’Arial’> DIVISIONS</StyleOverride>
 
You can get above string through running the following VBA code after you created a needed Leader note from UI:
Sub test()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim s As String
    s = oDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText
    Debug.Print s
End Sub

 
Delete that Leader note from UI, then select the curve (circle in this case) to which the LeaderNote is appended, and run the following VBA code to create the LeaderNote through API:

Sub CreateLN()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim s As String
s = "<StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HoleQuantity’ Precision=’0′>8</Parameter></StyleOverride><StyleOverride Font=’Arial’> HOLES ON DIA </StyleOverride><StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HolePCD’ Precision=’0′>35</Parameter></StyleOverride><StyleOverride Font=’Arial’>±0.1 </StyleOverride><Br/><StyleOverride Font=’Arial’>WITH </StyleOverride><StyleOverride Font=’Arial’><Parameter Resolved=’True’ ComponentIdentifier=’C:\Users\hanb\Documents\Disc.ipt’ Name=’HoleQuantity’ Precision=’0′>8</Parameter></StyleOverride><StyleOverride Font=’Arial’> DIVISIONS</StyleOverride>"
 
Dim curve As DrawingCurve
Set curve = oDoc.SelectSet.Item(1).Parent
Dim oGI1 As GeometryIntent
Set oGI1 = oDoc.ActiveSheet.CreateGeometryIntent(curve, kCenterPointIntent)
 
Dim pt As Point2d
Set pt = ThisApplication.TransientGeometry.CreatePoint2d
 
pt.X = curve.CenterPoint.X + 3
pt.Y = curve.CenterPoint.Y + 5
 
Dim oObjCol As ObjectCollection
Set oObjCol = ThisApplication.TransientObjects.CreateObjectCollection
oObjCol.Add pt
oObjCol.Add oGI1
 
Dim oLN As LeaderNote
‘ create a LeaderNote.
Set oLN = oDoc.ActiveSheet.DrawingNotes.LeaderNotes.Add(oObjCol, "")
oLN.FormattedText = s
End Sub

Note: Above string named "s" can be changed to accommodate other parameter and properties, such as Model parameter, part number property.


Comments

One response to “Create Leader Note with the Value of User or Model Parameter or Document Property”

  1. Le Yu Avatar
    Le Yu

    How do you delete the leader line and arrow through API?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading