Inventor 论坛上客户有个模型,其中有一些工作面
在插入到图纸时,可以通过选项控制是否将工作特征纳入到图纸中。
但比较遗憾的是,工作特征的名字没有显示在线条的旁边。客户问是否有办法添加上去。
通过一些研究发现,这些线条是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
不过问题又来了,由于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
推荐阅读
如何让general note 能按高宽调整显示
http://forums.autodesk.com/t5/inventor-customization/set-generalnote-fitted/td-p/4932886