为图纸中的工作特征增加注释

Inventor 论坛上客户有个模型,其中有一些工作面


image

在插入到图纸时,可以通过选项控制是否将工作特征纳入到图纸中。


image


image


但比较遗憾的是,工作特征的名字没有显示在线条的旁边。客户问是否有办法添加上去。


通过一些研究发现,这些线条是CenterLine对象,它们的ModelWorkFeature告知对应的工作特征信息,包括名字。而选用什么样的对象作为注释呢?我认为添加GeneralNote最简单,以下是测试代码和结果:


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


image


不过问题又来了,由于GeneralNote和CenterLine没有绑定关系,当CenterLine发生变化例如视图移动,则那些GeneralNote不会随着移动。当然可以监控OnChange事件,当视图发生变化,做相应的更新。不过这有点麻烦。

最后我选用了LeaderNote。它可以绑定到某个点。而且也可以简化为箭头和线条都没有的Leader。例如用以下的代码,可以生成与CenterLine绑定的注释。


  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

 

        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

                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

                    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
                        oPos = oEndPos

                    Else
                        ' set position of drawing note at start point
                        oPos = oStPos

                    End If
                End If
 

                Dim oWP_Name As String
                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)

 

            End If
        Next
 

    End Sub

   image



推荐阅读

如何让general note 能按高宽调整显示

http://forums.autodesk.com/t5/inventor-customization/set-generalnote-fitted/td-p/4932886


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值