Hello all,
I am trying to create some iLogic to automatically attach a specific Sketch Symbol to all feature control frames in a drawing (in Inventor 2017). I can place the symbol 'near' the FCF but can't actually successfully attach a leader to any Geometry Intent on the FCF object (so any relocation of the FCF will bring the Sketch Symbol along with it). The code is below. The program crashes when adding the leader.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSht As Inventor.Sheet
oSht = oDoc.ActiveSheet
Dim oLeaderPoints As ObjectCollection
oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
Dim oGeometryIntent As GeometryIntent
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim originPt As Point2d
Dim fcf As FeatureControlFrame
'Add inspection bubble symbol from library (will not crash if symbol already added)
Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
oSketchSymLib = oDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("KTR Inspection Sketch Symbols")
Dim oSymDef As SketchedSymbolDefinition
oSymDef = oDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, "Dimension Balloon", True)
For Each fcf In oSht.FeatureControlFrames
If fcf.Notes = "" Then ' Change to check for balloons
While existingInspNums.Contains(dimCtr) = True
dimCtr = dimCtr + 1
End While
sPromptStrings(0) = CStr(dimCtr)
oSymbol = oSht.SketchedSymbols.Add(oSymDef, oTG.CreatePoint2d(fcf.Position.X,fcf.Position.Y+1.2), 0, 1, sPromptStrings)
originPt = oTG.CreatePoint2d(oSymbol.Position.X,oSymbol.Position.Y)
oGeometryIntent = oSht.CreateGeometryIntent(fcf,fcf.Position)
oLeaderPoints.Clear
oLeaderPoints.Add(originPt)
oLeaderPoints.Add(oGeometryIntent)
oSymbol.Leader.AddLeader(oLeaderPoints) 'Program crashes on this line
oSymbol.LeaderVisible = False
dimCtr = dimCtr + 1
End If
Next