Attach a sketched symbol to a balloon

By Xiaodong Liang

I got a question on how to attach a sketched symbol to a balloon. This when the balloon moves, the sketched symbol can also move together. UI can do this, however the customer was struggling to make an API code.

I took some time to dig into. It looks there are some tricks here. Let us firstly take a look at how UI works.

  • select the sketched symbol
    – in mouse-right-button menu, select [Add Vertex / Leader]

image

  • Inventor will ask you to select a position. When the cursor is closing to the balloon, the cursor will become a cross if it locates on the balloon circle. On other locations such as balloon center or the leader line of the balloon, the cursor will still be an arrow. That means the valid locations on a balloon is the position on the circle.

image

So we need to make sure to create the geometry intent of balloon with the point on the circumference. While the customer’s code uses center point of the circle. So API failed.

One more thing I found is: in UI, you add the first leader point on balloon, next a position on sketched symbol. But with API, you must add them in the reverse sequence.

The following code assumes you have a drawing with one balloon and one sketched symbol.

VBA:

Public Sub AttachSymbolToBalloon()

  ‘ 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

  ‘ This assumes that a Balloon and SketchedSymbol are selected
  Dim oBalloon As Balloon
  Set oBalloon = oDrawDoc.SelectSet.Item(1)

   Dim oSS As SketchedSymbol
   Set oSS = oDrawDoc.SelectSet.Item(2)

   ‘ the collection of leader points SketchedSymbol
   Dim oObjColl As ObjectCollection
   Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection()
   ‘ first leader point is position of SketchedSymbol
    Dim oFirstPt1 As Point2d
    Set oFirstPt1 = ThisApplication.TransientGeometry.CreatePoint2d(oSS.Position.X, oSS.Position.Y)
    ‘second leader point on circumference of Balloon
    Dim oPtItent  As Point2d
    Set oPtItent = ThisApplication.TransientGeometry.CreatePoint2d( _
    oBalloon.Position.X + oBalloon.Style.BalloonDiameter / 2, _
       oBalloon.Position.Y)
    Dim oBalloonIntent  As GeometryIntent
    Set oBalloonIntent = oActiveSheet.CreateGeometryIntent(oBalloon, oPtItent)

     ‘ make sure the adding sequence
     Call oObjColl.Add(oFirstPt1)
      Call oObjColl.Add(oBalloonIntent)
    ‘ add leader.
    Call oSS.Leader.AddLeader(oObjColl)
End Sub

 

VB.NET

Public Sub AttachSymbolToBalloon()                 ' Set a reference to the drawing document.            ' This assumes a drawing document is active.            Dim oDrawDoc As DrawingDocument            oDrawDoc = ThisApplication.ActiveDocument                 ' Set a reference to the active sheet.            Dim oActiveSheet As Sheet            oActiveSheet = oDrawDoc.ActiveSheet                 ' This assumes that a Balloon and SketchedSymbol are selected            Dim oBalloon As Balloon            oBalloon = oDrawDoc.SelectSet.Item(1)                 Dim oSS As SketchedSymbol            oSS = oDrawDoc.SelectSet.Item(2)                 ' the collection of leader points SketchedSymbol            Dim oObjColl As ObjectCollection            oObjColl = ThisApplication.TransientObjects.CreateObjectCollection()                 ' first leader point is position of SketchedSymbol            Dim oFirstPt1 As Point2d            oFirstPt1 = ThisApplication.TransientGeometry.CreatePoint2d(oSS.Position.X, oSS.Position.Y)                 'second leader point on circumference of Balloon            Dim oPtItent As Point2d            oPtItent = ThisApplication.TransientGeometry.CreatePoint2d( _            oBalloon.Position.X + oBalloon.Style.BalloonDiameter / 2, _               oBalloon.Position.Y)                  Dim oBalloonIntent As GeometryIntent            oBalloonIntent = oActiveSheet.CreateGeometryIntent(oBalloon, oPtItent)                 ' make sure the adding sequence            Call oObjColl.Add(oFirstPt1)            Call oObjColl.Add(oBalloonIntent)                 ' add leader.            Call oSS.Leader.AddLeader(oObjColl)        End Sub

 image


Comments

2 responses to “Attach a sketched symbol to a balloon”

  1. John C Avatar
    John C

    Hello,
    I was wondering if you could please post a blog about how to attach a balloon to an existing one?
    Thank you much!

  2. Klaas De Smedt Avatar
    Klaas De Smedt

    Hi, I’m trying to achieve the same thing but instead of a balloon, I want the leader to attach to a Feature Control Frame Object but I get an error in return. I think this is a bug in Inventor 2018.
    I also want to attach a leader to a Surface Texture Symbol Object but I get the same error.
    Attaching to Dimensions or Drawing curves seems to work, so my error is in selecting the correct intent.
    When I investigate an existing Leader attached to an Feature Control Frame, the intent of the leader seems the same as the one I’m creating.
    Thanks to look into this.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading