我们知道,工程图里的引线一般会和某个视图几何线绑定,作为对其的注释。当曲线发生变化,引线位置和内容也会联动。那如何得知引线注释的是哪个零件或装配?其实思路就是得到其绑定的几何线。以下是一段小小的代码样例,假定先选中一个引线(API对象是LeaderNote)。
Sub test()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
'选取一个引线
Dim oLeaderNote As LeaderNote
Set oLeaderNote = oDoc.SelectSet(1)
'获得其Leader中最后一个节点,该节点指向几何线
Dim oLastNode As LeaderNode
Set oLastNode = oLeaderNote.Leader.AllNodes(oLeaderNote.Leader.AllNodes.Count)
Dim oGeIntent As GeometryIntent
Dim oAttachedDrawingCurve As DrawingCurve
Dim oDrawingView As DrawingView
Dim oModelG As Object
'查看是否该引线和几何线绑定
If Not oLastNode.AttachedEntity Is Nothing Then
'得到对应的几何线
Set oGeIntent = oLastNode.AttachedEntity
Set oAttachedDrawingCurve = oGeIntent.Geometry
'得到几何线所在视图
Set oDrawingView = oAttachedDrawingCurve.Parent
' 查看该曲线属于哪个零件或装配
'几何线对应的模型实体
Set oModelG = oAttachedDrawingCurve.ModelGeometry
If TypeOf oModelG Is Edge Then
'模型实体的SurfaceBody
Dim oSB As SurfaceBody
Set oSB = oModelG.Parent
'得知SurfaceBody所在的component definition
Dim oDef As ComponentDefinition
Set oDef = oSB.ComponentDefinition
'得到对应文档
Dim oSourceDoc As Document
Set oSourceDoc = oDef.Document
End If
MsgBox "引线注释的视图是: " & oDrawingView.Name & vbCr & "注释的对应模型文档是: " & oSourceDoc.FullFileName
Else
MsgBox ("该引线和任何几何线无关联!")
End If
End Sub