iLogic to attach balloon to an existing balloon

iLogic to attach balloon to an existing balloon

berry.lejeune
Advocate Advocate
1,410 Views
5 Replies
Message 1 of 6

iLogic to attach balloon to an existing balloon

berry.lejeune
Advocate
Advocate

Hello everyone,

I was wondering if there's a code that I can run to attach a balloon to an existing balloon like in the pictures below.

I've got to do several drawings like this with a lot of balloons. 

This will save me a lot of clicking time

 

Screenshot_718.png

 

Screenshot_717.png

 

Thanks

0 Likes
Accepted solutions (1)
1,411 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @berry.lejeune.  Are you creating and placing all of those original balloons by code, or manually, before you will be wanting to attach another balloon to an existing one.  If they were created manually, then how would you want an iLogic rule to behave for how to specify which balloon to add another balloon to, and how to specify which balloon to add to it?  Do you want to use the 'Pick' method to manually select the existing balloon after you start the rule, or do you want to pre-select a balloon before you start the rule?  Then how do you want to specify which other balloon to add to it?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @berry.lejeune.  Here is an example iLogic rule which uses the 'Pick' method I mentioned.  So, after you run the rule, it will prompt you to select an existing Balloon with your mouse, then proceed with the rest of the code.  The Inventor API process for attaching an extra balloon to an existing balloon requires us to specify either an Inventor.DrawingBOMRow type object, or an Inventor.ComponentOccurrence type object as the input for specify which balloon to add.  The extra Balloon is added to an existing Balloon using the Balloon.BalloonValueSets.Add() method.  Since I am still not sure how you want to specify which Balloon to add, I decided to use a Dictionary type collection variable.  Those can store a list of pairs of data, with each pair having a Key, and a Value (similar to a NameValueMap).  I choose to get the parent DrawingBOM object from the existing Balloon that you select, then loop through its rows, adding the referenced Document.DisplayName (or maybe the ItemNumber) as the Key of each pair, and either the DrawingBOMRow or the ComponentOccurrence as the Value of each pair.  Then it should present you with a list of those DisplayNames, allowing you to choose one.  Then it gets the associated DrawingBOMRow or ComponentOccurrence object, and uses that in the BalloonValueSets.Add method.  I left a lot of lines in there and commented out, so you can play around with which combination may work best for you.

Dim oBalloon As Inventor.Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon.")
If oBalloon Is Nothing Then Exit Sub
Dim oDBOM As DrawingBOM = oBalloon.BalloonValueSets.Item(1).ReferencedRow.Parent
Dim oDict As New Dictionary(Of String, Inventor.DrawingBOMRow)
'Dim oDict As New Dictionary(Of String, Inventor.ComponentOccurrence)
For Each oRow As DrawingBOMRow In oDBOM.DrawingBOMRows
	Dim oRowDoc As Inventor.Document = Nothing
	'Dim sItemNum As String = ""
	'Dim oRowOcc1 As ComponentOccurrence = Nothing
	Try : oRowDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document : Catch : End Try
	'Try : oRowOcc1 = oRow.BOMRow.ComponentOccurrences.Item(1) : Catch : End Try
	'Try : sItemNum = oRow.BOMRow.ItemNumber : Catch : End Try
	If oRowDoc Is Nothing Then Continue For
	oDict.Add(oRowDoc.DisplayName, oRow)
	'oDict.Add(oRowDoc.DisplayName, oRowOcc1)
Next
Dim sChosen As String = InputListBox("Choose one.", oDict.Keys.ToArray, "", "Document DisplayNames")
If sChosen = "" Then Exit Sub
Dim oDBOMRow As DrawingBOMRow = oDict.Item(sChosen)
oBalloon.BalloonValueSets.Add(oDBOMRow)
'Dim oOcc As ComponentOccurrence = oDict.Item(sChosen)
'oBalloon.BalloonValueSets.Add(oOcc)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

Luis_Pacheco_3D
Advocate
Advocate

Hi @WCrihfield I took your code and changed a little to do something I need.

 

 

Dim oBalloon As Inventor.Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Selecciona un globo.")
If oBalloon Is Nothing Then Exit Sub

Dim oDBOM As DrawingBOM = oBalloon.BalloonValueSets.Item(1).ReferencedRow.Parent
Dim oDict As New Dictionary(Of String, Inventor.DrawingBOMRow)

For Each oRow As DrawingBOMRow In oDBOM.DrawingBOMRows
    Dim oRowDoc As Inventor.Document = Nothing
    Try
        oRowDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document
    Catch
    End Try

    If oRowDoc Is Nothing Then Continue For

    Dim docDisplayName As String = oRowDoc.DisplayName
    If Not oDict.ContainsKey(docDisplayName) Then
        oDict.Add(docDisplayName, oRow)
    End If
Next

Dim sChosen As String = InputListBox("Elige uno.", oDict.Keys.ToArray, "", "Nombres de documentos")
Dim sText As String = InputBox("Introduzca un valor para el globo", "Título", "Entrada predeterminada")

If sChosen = "" Then Exit Sub

Dim oDBOMRow As DrawingBOMRow = oDict(sChosen)
Dim oBalloonValueSet As BalloonValueSet = oBalloon.BalloonValueSets.Add(oDBOMRow)
oBalloonValueSet.OverrideValue = sText
oBalloon.PlacementDirection = kbottomDirection

 

The code works for me, but, Is there another way to do what I'm trying to do? 

 

 

Message 5 of 6

berry.lejeune
Advocate
Advocate

@WCrihfield 

sorry for the late reply but you're code is working. Thank you

0 Likes
Message 6 of 6

J_Pfeifer_
Advocate
Advocate

Is it possible to somehow pass a custom table item into this situation? I don't use BOM and Component occurrences. I have a tool that simply places balloons iterating through a custom table. What I'd like is to pass all the row items into a collection, then use that to create an inputlistbox allowing the user to select the item they'd like to "attach from list" onto a balloon selection.  

 

Having a hard time reading this let alone manipulate it to my needs with tables. Theoretically, is it possible to create objects that simply represent the name or string from the custom table, then try to pass this back into a new Balloon value set? 

 

@WCrihfield 

0 Likes