Question
I try to write a program which looks for components that are not attached with a balloon in each drawing. How could I search for the them?
Solution
There is not a direct API, but you can collect all components that has balloon. And filter out the components that has not balloon from all referenced documents of the drawing.
The VBA code assumes a drawing is opened with some balloons. It iterates each balloon of each sheet, get its referenced document. Finally, iterate each referenced document of the drawing, and filter out the documents that has not balloon.
Public Sub CreateBalloon()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oBalloon As Balloon
‘array to store the documents that have balloon
Dim oBolloonedDocs() As String
Dim index As Integer
index = 1
For Each oSheet In oDrawDoc.Sheets
For Each oBalloon In oSheet.Balloons
Dim oBalloonValueSet As BalloonValueSet
For Each oBalloonValueSet In
oBalloon.BalloonValueSets
Dim strDisplay As String
strDisplay = "Balloon Item Number: "
' Add the balloon item number
(the overridden value if there is one)
If oBalloonValueSet.OverrideValue = "" Then
strDisplay = strDisplay & oBalloonValueSet.value
Else
strDisplay = strDisplay &
oBalloonValueSet.OverrideValue
End If
Dim oDrawingBOMRow As DrawingBOMRow
Set oDrawingBOMRow =
oBalloonValueSet.ReferencedRow
If oDrawingBOMRow.Custom Then
' The referenced item is a custom parts list row.
strDisplay = strDisplay & vbNewLine &
"Referenced Component(s):"
strDisplay = strDisplay & vbNewLine & "
Custom PartsList Row"
Else
Dim oBOMRow As BOMRow
Set oBOMRow = oDrawingBOMRow.BOMRow
' Add the Item Number from the model BOM.
strDisplay = strDisplay & vbNewLine & "BOM Item
Number: " & oBOMRow.ItemNumber
strDisplay = strDisplay & vbNewLine &
"Referenced Component(s):"
Dim oCompDefs As
ComponentDefinitionsEnumerator
Set oCompDefs =
oBOMRow.ComponentDefinitions
If oDrawingBOMRow.Virtual Then
' The referenced item is a virtual component.
strDisplay = strDisplay & vbNewLine & "
Virtual: " & oCompDefs.Item(1).DisplayName
Else
' Add the document name of the referenced component.
' There could be multiple if the balloon references
' a merged BOM row in the model.
Dim oCompDef As ComponentDefinition
For Each oCompDef In oCompDefs
strDisplay = strDisplay & vbNewLine & " " & oCompDef.Document.FullDocumentName
ReDim Preserve oBolloonedDocs(index)
oBolloonedDocs(index) = oCompDef.Document.FullDocumentName
index = index + 1
Next
End If
End If
'MsgBox strDisplay
Next
Next
Next
' check which document has not been ballooned
Dim oDrawEachRefDoc As Document
Dim oEachBalloonDoc As Variant
Dim oStri_Unballooned As String
oStri_Unballooned = "The document(s) that have not been ballooned" & vbCr
Dim oIsB As Boolean
For Each oDrawEachRefDoc In oDrawDoc.AllReferencedDocuments
oIsB = False
For Each oEachBalloonDoc In oBolloonedDocs
If oDrawEachRefDoc.FullDocumentName = oEachBalloonDoc Then
oIsB = True
Exit For
End If
Next
If oIsB = False Then
oStri_Unballooned = oStri_Unballooned & oDrawEachRefDoc.FullDocumentName & vbCr
End If
Next
Debug.Print oStri_Unballooned
End Sub