Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 516

Add Note for Centerline of Work Feature in Drawing

$
0
0

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

        oDoc = ThisApplication.ActiveDocument

 

        Dim oSheet As Sheet

        oSheet = oDoc.ActiveSheet

 

        Dim oCenterLine As Centerline

 

        ForEach oCenterLine In oSheet.Centerlines

            IfNot oCenterLine.ModelWorkFeature IsNothingThen

 

                'select start point or end point as the position for the drawing note

 

                Dim oPos As Point2d

 

                Dim oStPos As Point2d

                oStPos = oCenterLine.StartPoint

 

                Dim oEndPos As Point2d

                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

                        oPos = oStPos

                    Else

                        ' set position of drawing note at end point

                        oPos = oEndPos

                    EndIf

                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

                        oPos = oEndPos

                    Else

                        ' set position of drawing note at start point

                        oPos = oStPos

                    EndIf

                EndIf

 

                Dim oWP_Name AsString

                oWP_Name = oCenterLine.ModelWorkFeature.Name

 

                Dim sNote AsString

                sNote = "<StyleOverride Font='Arial' FontSize='0.2' Bold='True'>"& _

                        oWP_Name & _

                        "</StyleOverride>"

 

                Dim oGeneralNote As GeneralNote

                oGeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPos, sNote) 

 

            EndIf

        Next

 

    EndSub

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

        oDoc = ThisApplication.ActiveDocument

 

        Dim oTG As TransientGeometry

        oTG = ThisApplication.TransientGeometry

 

        Dim oActiveSheet As Sheet

        oActiveSheet = oDoc.ActiveSheet

 

        Dim oCenterLine As Centerline

 

        ForEach oCenterLine In oActiveSheet.Centerlines

            IfNot oCenterLine.ModelWorkFeature IsNothingThen

 

 

                'select start point or end point as the position for the drawing note

 

                Dim oPos As Point2d

 

                Dim oStPos As Point2d

                oStPos = oCenterLine.StartPoint

 

                Dim oEndPos As Point2d

                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

                        oPos = oStPos

                    Else

                        ' set position of drawing note at end point

                        oPos = oEndPos

                    EndIf

                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

                        oPos = oEndPos

                    Else

                        ' set position of drawing note at start point

                        oPos = oStPos

                    EndIf

                EndIf

 

                Dim oWP_Name AsString

                oWP_Name = oCenterLine.ModelWorkFeature.Name

 

 

                Dim oLeaderPoints As ObjectCollection

                oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection()

 

                Call oLeaderPoints.Add(oTG.CreatePoint2d( _

                                        oPos.X, _

                                        oPos.Y))

 

                ' Create geometry intent from position

                Dim oGeometryIntent As GeometryIntent

                oGeometryIntent = oActiveSheet.CreateGeometryIntent(oCenterLine, _

                                                     oPos)

 

                Call oLeaderPoints.Add(oGeometryIntent)

 

                ' add leader note

                Dim oLeaderNote As LeaderNote

                Call oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, oWP_Name)

 

            EndIf

        Next

 

    EndSub


Viewing all articles
Browse latest Browse all 516

Trending Articles