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]
- 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.
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