API - Tool for orientation annotations on drawingview

API - Tool for orientation annotations on drawingview

Jef_E
Collaborator Collaborator
657 Views
1 Reply
Message 1 of 2

API - Tool for orientation annotations on drawingview

Jef_E
Collaborator
Collaborator

Hi,

 

I'm currently working on a Tool that will serve as an annotating tool. It will add orientations based on centerlines that are placed on the model.

 

I currently made the part that does the main orientations 0° 90° 180° 270°. For this operation the user must select an centermark and then the tool adds the orientations as text (general note) on the end points of the centermark (see attached image).

 

Now I want to do the same based on the centerlines that are placed on the view. But i'm stuck... I would like to get a collection of all the centerlines that are in View "Test" but there isn't a collection available in Inventor.DrawingView there is only one in the sheet.

 

So my question: How can I get only the centerlines that are associated with the drawing view test. And not the collection of centerlines that are on the entire sheet?

 

Secondly. Is it possible to attach a general note to a view? So when you move the view, the general note moves with it?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
658 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni

You're right that the centerlines are associated with a sheet.  It is possible, although not that straightforward to figure out which view a centerline is associated with.  I've written a function that does this for the most common centerlines.  Hopefully that's all you have in your models but it is possible to extend it to work with the others that this is currently skipping it would just take me more time which I don't have right now.  Below is the function that given a view returns all of the centerlines associated with it.  The Sub was used to test it.

 

Public Sub TestGetCenterLines()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Get the first view on the sheet.
    Dim view As DrawingView
    Set view = oActiveSheet.DrawingViews.Item(1)
    
    Dim centerLines As ObjectCollection
    Set centerLines = GetCenterLines(view)
    
    MsgBox ("There are " & centerLines.Count & " centerlines on the view " & view.name)
End Sub



Public Function GetCenterLines(view As DrawingView) As ObjectCollection
    Dim foundCenterLines As ObjectCollection
    Set foundCenterLines = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Iterate through the centerlines on the sheet the view is on.
    Dim drawCurve As DrawingCurve
    Dim cLine As Centerline
    For Each cLine In view.Parent.centerLines
        ' Get the objects the centerline is attached to.
        Dim intent As GeometryIntent
        If cLine.CenterlineType = kBisectorCenterlineType Then
            Dim intTwo As GeometryIntent
            Call cLine.GetBisectorEntities(intent, intTwo)
            
            ' Get the drawing curve from the geometryIntent.
            Set drawCurve = intent.Geometry
        ElseIf cLine.CenterlineType = kCenteredPatternCenterlineType Then
            Set intent = Nothing
        ElseIf cLine.CenterlineType = kRegularCenterlineType Then
            Dim fitPoint As Object
            Set fitPoint = cLine.FitPoints.Item(1)
            
            If TypeOf fitPoint Is GeometryIntent Then
                Set intent = fitPoint
            ElseIf TypeOf fitPoint Is Centermark Then
                Dim mark As Centermark
                Set mark = fitPoint
                If mark.CentermarkType = kRegularCentermarkType Then
                    If TypeOf fitPoint.AttachedEntity Is GeometryIntent Then
                        Set intent = fitPoint.AttachedEntity
                    End If
                Else
                    Set intent = Nothing
                End If
            End If
        ElseIf cLine.CenterlineType = kWorkFeatureCenterlineType Then
            Set intent = Nothing
        End If
                    
        If Not intent Is Nothing Then
            ' Get the drawing curve from the geometryIntent.
            Set drawCurve = intent.Geometry
            
            ' Check to see if this is in the correct view.
            If drawCurve.Parent Is view Then
                Call foundCenterLines.Add(cLine)
            End If
        End If
    Next
    
    Set GetCenterLines = foundCenterLines
End Function

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog