This is a question from a forum post. The customer has the model with some work planes.
When he inserts the model to a drawing, the [Display Options] allows to include work feature or not.
Finally, the work planes can be incldued and displayed in the sheet.
However, these lines are not noted. The customer wants to pull the names of each plane from the part and add them along with these lines.
It looks API has not a direct way to enable the name, but such lines are CenterLine object in Sheet. Centerline.ModelWorkFeature tells from which object the center line comes from. So we can get the name from ModelWorkFeature. While the challenge is which object we can create as a note. I think the easiest way would be a GeneralNote(DrawingNote). You can simply set its position and formatted text. This is a code demo of VBA.
Sub addDrawingNoteForWorkPlane()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet
Dim oCenterLine As Centerline
For Each oCenterLine In oSheet.Centerlines
If Not oCenterLine.ModelWorkFeature Is Nothing Then
'select start point or end point as the position for the drawing note
Dim oPos As Point2d
Dim oStPos As Point2d
Set oStPos = oCenterLine.StartPoint
Dim oEndPos As Point2d
Set oEndPos = oCenterLine.EndPoint
If Math.Abs(oStPos.X - oEndPos.X) > Math.Abs(oStPos.Y - oEndPos.Y) Then
' put drawing note at the right of the center line
If oStPos.X > oEndPos.X Then
' set position of drawing note at start point
Set oPos = oStPos
Else
' set position of drawing note at end point
Set oPos = oEndPos
End If
Else
' put drawing note at the bottom of the center line
If oStPos.Y > oEndPos.Y Then
' set position of drawing note at end point
Set oPos = oEndPos
Else
' set position of drawing note at start point
Set oPos = oStPos
End If
End If
Dim oWP_Name As String
oWP_Name = oCenterLine.ModelWorkFeature.Name
Dim sNote As String
sNote = "<StyleOverride Font='Arial' FontSize='0.2' Bold='True'>" & _
oWP_Name & _
"</StyleOverride>"
Dim oGeneralNote As GeneralNote
Set oGeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPos, sNote)
End If
Next
End Sub
The disadvantage of a GeneralNote is it is not attached to the center line. So when the center line is change (e.g. the drawing view is moved), the notes cannot be moved accordingly. So we have to delegate OnChange event and move the GeneralNote.
Then I turned to LeaderNote which can be attached to a point. You can have the simplest LeaderNote that has not line/arrow. e.g.
The relevant code is as below. You will need to calculate the best position for the note according to your workflow.
Sub addLeaderForWorkPlane()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oActiveSheet As Sheet
Set oActiveSheet = oDoc.ActiveSheet
Dim oCenterLine As Centerline
For Each oCenterLine In oActiveSheet.Centerlines
If Not oCenterLine.ModelWorkFeature Is Nothing Then
'select start point or end point as the position for the drawing note
Dim oPos As Point2d
Dim oStPos As Point2d
Set oStPos = oCenterLine.StartPoint
Dim oEndPos As Point2d
Set oEndPos = oCenterLine.EndPoint
If Math.Abs(oStPos.X - oEndPos.X) > Math.Abs(oStPos.Y - oEndPos.Y) Then
' put drawing note at the right of the center line
If oStPos.X > oEndPos.X Then
' set position of drawing note at start point
Set oPos = oStPos
Else
' set position of drawing note at end point
Set oPos = oEndPos
End If
Else
' put drawing note at the bottom of the center line
If oStPos.Y > oEndPos.Y Then
' set position of drawing note at end point
Set oPos = oEndPos
Else
' set position of drawing note at start point
Set oPos = oStPos
End If
End If
Dim oWP_Name As String
oWP_Name = oCenterLine.ModelWorkFeature.Name
Dim oLeaderPoints As ObjectCollection
Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection()
Call oLeaderPoints.Add(oTG.CreatePoint2d(oPos.X, oPos.Y))
' Create geometry intent from position
Dim oGeometryIntent As GeometryIntent
Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oCenterLine, oPos)
Call oLeaderPoints.Add(oGeometryIntent)
' add leader note
Dim oLeaderNote As LeaderNote
Call oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, oWP_Name)
End If
Next
End Sub