Attach leader to Note/Chamfer using API

Attach leader to Note/Chamfer using API

TA.Fehr
Advocate Advocate
1,050 Views
1 Reply
Message 1 of 2

Attach leader to Note/Chamfer using API

TA.Fehr
Advocate
Advocate

There are a few threads on this but none address my issue directly.

I'm able to attach sketched symbols to dimensions with a leader which allows the sketch symbol to follow the dimension. However, I can't seem to do this with chamfer notes and textual notes. 

 

The only way I can see that they differ from dimensions is that the "RangeBox" on the dimensional objects is nested within the "Text" subset (ie  for the dimension I would pass oDim.Text.Rangebox.MaxPoint whereas for the note I have to pass oDim .Rangebox.MaxPoint)

 

I assume the problem has something to do with the creation of the GeometryIntent, as this is the only real difference that would matter. But I'm not sure how else to direct the leader intent to the note.

 

The hangup is happening on the last step of the addleader command. What I have currently is:

 

 

    Private Sub AddBalloon(ByVal CurrRow As Integer, ByVal Insert As Boolean)
        Dim oDoc As DrawingDocument = _invApp.ActiveDocument
        Dim oInteraction As InteractionEvents = _invApp.CommandManager.CreateInteractionEvents
        oInteraction.StatusBarText = "Select a dimension"
        oSelect = oInteraction.SelectEvents
        oSelect.AddSelectionFilter(SelectionFilterEnum.kDrawingDimensionFilter)
        oSelect.SingleSelectEnabled = True
        oInteraction.Start()

        Dim oSheetSettings As SheetSettings = oDoc.SheetSettings
        Dim SelectedFeature = _invApp.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "") '.kAllEntitiesFilter, "Select something")
        If SelectedFeature Is Nothing Then Exit Sub
        Dim RefKeyValue() As Byte = New Byte() {}
        Call SelectedFeature.GetReferenceKey(RefKeyValue)
        Dim RefKey As String = _invApp.ActiveDocument.ReferenceKeyManager.KeyToString(RefKeyValue)
        Note(SelectedFeature, RefKey, Balloon)
    End Sub
    Public Sub Note(oDim As DrawingNote, RefKey As String, Balloon As Integer)
        InsertSketchedSymbolSample(oDim, oDim.RangeBox.MaxPoint, oDim.RangeBox.MinPoint, RefKey, Balloon)
    End Sub

 

 

 

 

 

Private Sub InsertSketchedSymbolSample(oDim As Object, ByRef MaxP As Point2d, ByRef MinP As Point2d, ByRef Values As String, ByRef Balloon As Integer) 
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = _invApp.ActiveDocument
        ' Obtain a sketched symbol definition.
        Dim oSketchedSymbolDef As SketchedSymbolDefinition = Nothing
        For i = 1 To oDrawDoc.SketchedSymbolDefinitions.Count
            If oDrawDoc.SketchedSymbolDefinitions.Item(i).Name = "Insp" Then
                oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item(i)
                Exit For
            End If
        Next
        If oSketchedSymbolDef Is Nothing Then
            CreateSketchedSymbolDefinition()
            For i = 1 To oDrawDoc.SketchedSymbolDefinitions.Count
                If oDrawDoc.SketchedSymbolDefinitions.Item(i).Name = "Insp" Then
                    oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item(i)
                    Exit For
                End If
            Next
        End If
        Dim oSheet As Sheet
        oSheet = oDrawDoc.ActiveSheet
        Dim sPromptStrings() As String = {Balloon, Values}
        ' Create sketched symbol
        Dim oTG As TransientGeometry
        oTG = _invApp.TransientGeometry
        Dim oPoint As Point2d 
                oPoint = oTG.CreatePoint2d(MinP.X - (0.1), MaxP.Y + (0.1))
        Dim oSketchedSymbol As SketchedSymbol
        Dim oGI As GeometryIntent
        oGI = oSheet.CreateGeometryIntent(oDim, oPoint)
        Dim oCol As ObjectCollection
        oCol = _invApp.TransientObjects.CreateObjectCollection
        oCol.Add(oPoint)
        oCol.Add(oGI)
        oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint, 0, 1, sPromptStrings)
' THIS IS WHERE THE ERROR OCURRS'

oSketchedSymbol.Leader.AddLeader(oCol) oSketchedSymbol.LeaderVisible = False End Sub Private Sub CreateSketchedSymbolDefinition() ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = _invApp.ActiveDocument ' Create the new sketched symbol definition. Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Insp") ' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates ' a copy of the sketched symbol definition's and opens it for edit. Dim oSketch As DrawingSketch = Nothing Call oSketchedSymbolDef.Edit(oSketch) Dim oTG As TransientGeometry oTG = _invApp.TransientGeometry Dim oInsertionPoint As Point2d = (oTG.CreatePoint2d(0, 0)) Dim oSketchCircle As SketchCircle oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), (0.1333)) Dim oSheetSettings As SheetSettings = oDrawDoc.SheetSettings Dim oColor As Color = _invApp.TransientObjects.CreateColor(oSheetSettings.SheetColor.Red, oSheetSettings.SheetColor.Green, oSheetSettings.SheetColor.Blue, 0) ' Add a prompted text field at the center of the sketch circle. Dim sText As String sText = "<StyleOverride FontSize='" & 0.2 & "'>" & "<Prompt>Number</Prompt>" & "</StyleOverride>" Dim oTextBox As Inventor.TextBox Dim ValueText As String = "<StyleOverride FontSize='" & 0.0001 & "'>" & "<Prompt>Value</Prompt>" & "</StyleOverride>" oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0, 0), sText) oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0, 0), ValueText) oTextBox.Color = oColor ' oTextBox.FormattedText = "<StyleOverride FontSize='0.08'></StyleOverride>" Call oSketchedSymbolDef.ExitEdit(True) End Sub

 

Accepted solutions (1)
1,051 Views
1 Reply
Reply (1)
Message 2 of 2

TA.Fehr
Advocate
Advocate
Accepted solution

I've solved the issue. 

The reason the leader was causing an error was that the API treats dimensions and leaders differently.

I was passing a dimension object to the leader creation sub, but when I passed a note object, I was able to create the leader correctly.

 

I had read over this blog before, but it never occurred to me to change the objects. Now I have two options in my create leader sub which needs to differentiate between the two. The change to the code is as follows:

 

        Dim oSketchedSymbol As SketchedSymbol
        Dim oGI As GeometryIntent
        Dim oCol As ObjectCollection
        oCol = _invApp.TransientObjects.CreateObjectCollection
        oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPoint, 0, 1, sPromptStrings)
        If Not Note Is Nothing Then
            Call oCol.Add(oPoint)
            oGI = oSheet.CreateGeometryIntent(Note, _invApp.TransientGeometry.CreatePoint2d(Note.Position.X, Note.Position.Y))
            Call oCol.Add(oGI)
        Else
            oGI = oSheet.CreateGeometryIntent(oDim, oPoint)
            oCol.Add(oGI)
            oCol.Add(oPoint)
        End If
        Call oSketchedSymbol.Leader.AddLeader(oCol)
        oSketchedSymbol.LeaderVisible = False
0 Likes