Get Model Document from LeaderNote

By Xiaodong Liang

As we know, the leader note could attach with a drawing curve. If the curve changes, the position and the content of the leader may change as well. Then, how to know which model document (part/assembly) the leader note points to? Actually, the clue is to get the drawing curve the leader note attached with.

Following code demo assumes a leader note is selected.

image

Sub test()

    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument

    ‘select a leader note
    Dim oLeaderNote As LeaderNote
    Set oLeaderNote = oDoc.SelectSet(1)

    ‘ get the last node of the leader which attaches to the drawing curve
    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

    ‘check if the leader attaches to a drawing curve
    If Not oLastNode.AttachedEntity Is Nothing Then

        ‘get the corresponding curve
        Set oGeIntent = oLastNode.AttachedEntity
        Set oAttachedDrawingCurve = oGeIntent.Geometry

        ‘get the drawing view
        Set oDrawingView = oAttachedDrawingCurve.Parent

        ‘ check which model document the curve comes from
        ‘the model entity
         Set oModelG = oAttachedDrawingCurve.ModelGeometry

         If TypeOf oModelG Is Edge Then

             ‘SurfaceBody
             Dim oSB As SurfaceBody
             Set oSB = oModelG.Parent
             ‘get the component definition of SurfaceBody
             Dim oDef As ComponentDefinition
             Set oDef = oSB.ComponentDefinition
             ‘get the document
             Dim oSourceDoc As Document
             Set oSourceDoc = oDef.Document
         End If

         MsgBox "drawing view is: " & oDrawingView.Name & vbCr & "the model document is: " & oSourceDoc.FullFileName

    Else
       MsgBox ("no any curve is attached with the leader note!")
    End If
End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading