Attach Leader Text to a balloon

Attach Leader Text to a balloon

Anonymous
Not applicable
759 Views
3 Replies
Message 1 of 4

Attach Leader Text to a balloon

Anonymous
Not applicable

Hello,

 

I'm having difficulty attaching leader text to a balloon, the reason for attaching to a balloon is so when the balloon is moved the text goes with it. When done manually the process is as follows: select add leader text from the ribbon, hover over a balloon and click on the necessary quadrant, right click and select continue, add the text you require then click ok and all is done.

 

I can add text by only adding one leader point, but the text is not associated with the balloon, when I add the geometry quadrant 2dpoint as a geometry intent the code fails on this line:  Dim oLeaderText As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, "Text to add here")

 

Please see the attached code.

 

Thanks in advance.

 

Paul

 

    Public Sub AttachLeaderTextToBalloon(oBalloon As Inventor.Balloon, ByVal Position As String, ByVal LeaderText As String)


        'Adds a Leader Text To A Balloon, Ballon To Be Parsed From The Call 
        'Along With The Positiion And The Text Value.

        'Dim oApp = ThisApplication

        'Ref This Document (The Active Document)
        Dim oDrawingDocument As Inventor.DrawingDocument
        oDrawingDocument = oApp.ActiveDocument

        'Ref The Sheet (The Active Document Sheet)
        Dim oSheet As Inventor.Sheet
        oSheet = oDrawingDocument.ActiveSheet

        Dim dBalloonDiameter As Double
        dBalloonDiameter = oBalloon.Style.BalloonDiameter

        'set whether to define the balloon size by text height
        oBalloon.Style.ScaleToTextHeight = True

        'Variables For The Balloon Positio
        Dim dBalloonPositionX As Double = Nothing
        Dim dBalloonPositionY As Double = Nothing


        ' Create Leader Points And Geometry Intent From Balloon.
        Select Case Position
            Case 0 ' Bottom Center (6 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y - (dBalloonDiameter / 2)
            Case 90 ' Mid Left (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X - (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
            Case 180 ' Mid Right (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y + (dBalloonDiameter / 2)
            Case 270 ' Top Center (12 O'clock)
                dBalloonPositionX = oBalloon.Position.X + (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
        End Select

        'Set Transient Geometry for This Application
        Dim oTG As TransientGeometry = oApp.TransientGeometry

        'Leader Point On Circumference Of Balloon
        Dim oPtItent As Point2d = Nothing

        ' Add the GeometryIntent to the leader points collection.
        ' This is the geometry that the balloon will attach to.
        Dim oBalloonIntent As GeometryIntent

        oPtItent = (oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        oBalloonIntent = oSheet.CreateGeometryIntent(oBalloon, oPtItent)

        'Set Leader Point Positions
        Dim oLeaderPoints As ObjectCollection = oApp.TransientObjects.CreateObjectCollection

        oLeaderPoints.Add(oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        'oLeaderPoints.Add(oBalloonIntent)

        'Add Leader Text To Balloon (Currently The Text Does Not Move With The Balloon, Requires More Work)
        Dim oLeaderText As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, "Text to add here")

        'Align The Text To The Right
        oLeaderText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextRight


    End Sub

 

 

 

 

 

0 Likes
760 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Sorry,

 

I posted to early, got it working, it was just a setting in the styles.

 

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

'set whether to define the balloon size by text height

oBalloon.Style.ScaleToTextHeight = False

oBalloon.Style.StretchBalloonToText = False

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

also I found another way around it by using sketched symbols with prompted entries.

 

Please see code below if you're interested.

 

Thanks

 

Paul

Public Sub AttachLeaderTextToBalloon(oBalloon As Inventor.Balloon, ByVal Position As String, _
                                         ByVal LeaderText As String, ByVal BalloonNumberId As Integer, _
                                         Optional ByVal AddAttribute As Boolean = False)


        'Adds a Leader Text To A Balloon, Balloon To Be Parsed From The Call 
        'Along With The Positiion And The Text Value.

        'Dim oApp = ThisApplication

        'Ref This Document (The Active Document)
        Dim oDrawingDocument As Inventor.DrawingDocument
        oDrawingDocument = oApp.ActiveDocument

        'Ref The Sheet (The Active Document Sheet)
        Dim oSheet As Inventor.Sheet
        oSheet = oDrawingDocument.ActiveSheet

        Dim dBalloonDiameter As Double
        dBalloonDiameter = oBalloon.Style.BalloonDiameter

        'set whether to define the balloon size by text height
        oBalloon.Style.ScaleToTextHeight = False
        oBalloon.Style.StretchBalloonToText = False

        'Variables For The Balloon Positio
        Dim dBalloonPositionX As Double = Nothing
        Dim dBalloonPositionY As Double = Nothing


        ' Create Leader Points And Geometry Intent From Balloon.
        Select Case Position
            Case 0 ' Bottom Center (6 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y - (dBalloonDiameter / 2)
            Case 90 ' Mid Left (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X - (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
            Case 180 ' Mid Right (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y + (dBalloonDiameter / 2)
            Case 270 ' Top Center (12 O'clock)
                dBalloonPositionX = oBalloon.Position.X + (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
        End Select

        'Set Transient Geometry for This Application
        Dim oTG As TransientGeometry = oApp.TransientGeometry

        'Leader Point On Circumference Of Balloon
        Dim oPtItent As Point2d = Nothing

        ' Add the GeometryIntent to the leader points collection.
        ' This is the geometry that the balloon will attach to.
        Dim oBalloonIntent As GeometryIntent

        oPtItent = (oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        oBalloonIntent = oSheet.CreateGeometryIntent(oBalloon, oPtItent)

        'Set Leader Point Positions
        Dim oLeaderPoints As ObjectCollection = oApp.TransientObjects.CreateObjectCollection

        oLeaderPoints.Add(oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        oLeaderPoints.Add(oBalloonIntent)

        'Add Leader Text To Balloon (Currently The Text Does Not Move With The Balloon, Requires More Work)
        Dim oLeaderText As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, LeaderText)


        ' Align The Text Correctly Dependant On Balloon Position.
        Select Case Position
            Case 0 ' Bottom Center (6 O'clock)
                'Align The Text To The Bottom/Center
                oLeaderText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
                oLeaderText.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextUpper
            Case 90 ' Mid Left (9 O'clock)
                'Align The Text To The Right
                oLeaderText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextRight
            Case 180 ' Mid Right (9 O'clock)
                'Align The Text To The Top/Center
                oLeaderText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
                oLeaderText.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextLower
            Case 270 ' Top Center (12 O'clock)
                'Align The Text To The Left
                oLeaderText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
        End Select

        'Add Attributes To Sketched Symbol
        If AddAttribute = True Then

            'The Following Code Adds The LeaderText Which Has Just Been Created "oLeaderText" 
            'To A Attribute Set Called "oLeaderTextToDelete" This Then Enables The Dim "oLeaderText"
            'To Be Identified And Deleted If Needed.

            ' Add the attributes to the Dimension which has just been added
            Dim attbSets As AttributeSets = oLeaderText.AttributeSets

            'Checks If Attribute Set Already Exists
            If Not attbSets.NameIsUsed("oLeaderTextToDelete") Then
                'Creates Attribute Set
                Dim attbSet As AttributeSet = attbSets.Add("oLeaderTextToDelete")
                'Adds Attribute And Value To "oLeaderTextToDelete" 
                Dim attb As Inventor.Attribute = _
                       attbSet.Add("oLeaderTextGroup1", ValueTypeEnum.kStringType, BalloonNumberId)
            End If
        End If


    End Sub

 

Code for Sketched Symbol:

 

Public Sub AttachSketchedSymbolToBalloon(oBalloon As Inventor.Balloon, ByVal SketchedSymbolName As String, _
                                             ByVal Position As String, ByVal PromtedTextLine1 As String, _
                                             ByVal BalloonNumberId As Integer, Optional ByVal AddAttribute As Boolean = False)


        'Adds a Sketched Symbol To A Balloon, Ballon To Be Parsed From The Call 
        'Along With The Positiion And The Text Value.

        'Dim oApp = ThisApplication

        'Ref This Document (The Active Document)
        Dim oDrawingDocument As Inventor.DrawingDocument
        oDrawingDocument = oApp.ActiveDocument

        'Ref The Sheet (The Active Document Sheet)
        Dim oSheet As Inventor.Sheet
        oSheet = oDrawingDocument.ActiveSheet

        Dim dBalloonDiameter As Double
        dBalloonDiameter = oBalloon.Style.BalloonDiameter

        'set whether to define the balloon size by text height
        oBalloon.Style.ScaleToTextHeight = False
        oBalloon.Style.StretchBalloonToText = False

        'Variables For The Balloon Positio
        Dim dBalloonPositionX As Double = Nothing
        Dim dBalloonPositionY As Double = Nothing


        ' Create Leader Points And Geometry Intent From Balloon.
        Select Case Position
            Case 0 ' Bottom Center (6 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y - (dBalloonDiameter / 2)
            Case 90 ' Mid Left (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X - (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
            Case 180 ' Mid Right (9 O'clock)
                dBalloonPositionX = oBalloon.Position.X
                dBalloonPositionY = oBalloon.Position.Y + (dBalloonDiameter / 2)
            Case 270 ' Top Center (12 O'clock)
                dBalloonPositionX = oBalloon.Position.X + (dBalloonDiameter / 2)
                dBalloonPositionY = oBalloon.Position.Y
        End Select

        'Set Transient Geometry for This Application
        Dim oTG As TransientGeometry = oApp.TransientGeometry

        'Leader Point On Circumference Of Balloon
        Dim oPtItent As Point2d = Nothing

        ' Add the GeometryIntent to the leader points collection.
        ' This is the geometry that the balloon will attach to.
        Dim oBalloonIntent As GeometryIntent

        oPtItent = (oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        oBalloonIntent = oSheet.CreateGeometryIntent(oBalloon, oPtItent)

        'Set Leader Point Positions
        Dim oLeaderPoints As ObjectCollection = oApp.TransientObjects.CreateObjectCollection

        oLeaderPoints.Add(oTG.CreatePoint2d(dBalloonPositionX, dBalloonPositionY))
        oLeaderPoints.Add(oBalloonIntent)


        ' Get the first symbol definition, Symbol can be named as a string
        Dim oSketchSymbol As SketchedSymbolDefinition = oDrawingDocument.SketchedSymbolDefinitions(SketchedSymbolName)


        ' This sketched symbol definition contains two prompted string inputs. An array
        ' must be input that contains the strings for the prompted strings.
        Dim sPromptStrings(0) As String
        'Weld Size 
        sPromptStrings(0) = PromtedTextLine1


        ' Create the symbol with a leader
        Dim oSketchedSymbol As SketchedSymbol
        oSketchedSymbol = oSheet.SketchedSymbols.AddWithLeader(oSketchSymbol, oLeaderPoints, 0.0, 1, sPromptStrings)


        'set whether to define the balloon size by text height
        oBalloon.Style.StretchBalloonToText = True

        'Add Attributes To Sketched Symbol
        If AddAttribute = True Then

            'The Following Code Adds The SketchedSymbol Which Has Just Been Created "oSketchedSymbol" 
            'To A Attribute Set Called "oSketchedSymbolToDelete" This Then Enables The Dim "oSketchedSymbol"
            'To Be Identified And Deleted If Needed.

            ' Add the attributes to the Dimension which has just been added
            Dim attbSets As AttributeSets = oSketchedSymbol.AttributeSets

            'Checks If Attribute Set Already Exists
            If Not attbSets.NameIsUsed("oSketchedSymbolToDelete") Then
                'Creates Attribute Set
                Dim attbSet As AttributeSet = attbSets.Add("oSketchedSymbolToDelete")
                'Adds Attribute And Value To "oSketchedSymbol" 
                Dim attb As Inventor.Attribute = _
                       attbSet.Add( _
                       "oSketchedSymbolGroup1", ValueTypeEnum.kStringType, BalloonNumberId)
            End If
        End If


    End Sub
0 Likes
Message 3 of 4

Anonymous
Not applicable
I thank you for figuring this out. After a few minor tweaks I have this working for my drawings. The problem I am facing however is that once I call AttachLeaderTextToBalloon, all of my balloons are resized and begin to overlap (see attachment). Is there any way to keep ScaleToTextHeight set to true or am I going to have to set it back after?
0 Likes
Message 4 of 4

Anonymous
Not applicable

Is there a way to detect balloons that are attached to balloons. I'd like to put the Quantity of the first Balloon part on the drawing so that it is attached to the last attached balloon.

 

adjacent_balloons.jpg

 

So what i'd like is the qty for #21 to be attached to right right of #23.

 

Perhaps just knowing how to detect adjacent balloons would be helpful. There are scenarios where there are 3 or more adjacent balloons in our drawings.

 

0 Likes