Add Note for Centerline of Work Feature in Drawing

By Xiaodong Liang

This is a question from a forum post. The customer has the model with some work planes.

image

When he inserts the model to a drawing, the [Display Options] allows to include work feature or not.

image

Finally, the work planes can be incldued and displayed in the sheet.

image

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
  &#16
0;             Set oGeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPos, sNote)
 
            End If
        Next
 
    End Sub

image

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.

image

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()

  &
#160;            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


Comments

4 responses to “Add Note for Centerline of Work Feature in Drawing”

  1. Jörg Weber Avatar
    Jörg Weber

    Hi Xiaodong Liang
    that sounds very good. Specaliy last ime a customer from me ask for that function.
    I’m not a programmer, so I copy and paste teh code in the VB-Editor and let it run. But it cames a error at this line
    oDoc = ThisApplication.ActiveDocument
    I have a german invento 2015. But i think thats not the reason of the error.
    Have you any idea what i can do ?

  2. Hi Jörg,
    apologize! I simply put the VBA code to a format tool in order to have a nicer code lines,but applied with VB.NET format. Now I copied the VBA code directly. It should work now.

  3. Hi Xianodong,
    thanks for your help.
    I follow your steps and now it works fine.
    Very nice makro.
    thanks a lot

  4. Hi Xianodong,
    Thanks for the code. I’m trying to use it for placing some symbols at each start and end of centerline of work feature. It works ok, but I need to improve it. First I need to do it per view selection, at this moment the code will add symbols to all centerlines found on the drawings, but I need only for selected views. Should be possible and easy, however I can’t get it done. Please help if you can.
    Thanks

Leave a Reply to Xiaodong LiangCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading