CODE TO ATTACH BALLOONS FROM LIST WITH MATCHING PROPERTY

CODE TO ATTACH BALLOONS FROM LIST WITH MATCHING PROPERTY

eric.smyth
Participant Participant
273 Views
5 Replies
Message 1 of 6

CODE TO ATTACH BALLOONS FROM LIST WITH MATCHING PROPERTY

eric.smyth
Participant
Participant

I am trying to piece together, with my limited iLogic abilities, to have a code that will allow you to select a balloon and then automatically attach balloons from list that have the matching custom ipropery value. When I have multiple parts in a view that cover each other I would select to add from list and do so. the parts list is quite long so this manually takes a long time. Would anyone have something like this?

0 Likes
274 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @eric.smyth ,

See this example to get you started.

Hope this helps,

Curtis

 

 

Dim oBalloon As Inventor.Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a balloon.")
If oBalloon Is Nothing Then Exit Sub

Dim oRow As DrawingBOMRow
Dim oTargetDoc As Inventor.Document
Dim oRowDoc As Inventor.Document
Dim oDBOM As DrawingBOM = oBalloon.BalloonValueSets.Item(1).ReferencedRow.Parent

For Each oRow In oDBOM.DrawingBOMRows	
	If oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value Then		
		oTargetDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document		
	End If
Next

If oTargetDoc Is Nothing Then Exit Sub	

Dim CustomPropSet As PropertySet
oTargetDocCustomPropSet = oTargetDoc.PropertySets.Item("Inventor User Defined Properties")
oTargetDocPropValue = oTargetDocCustomPropSet.Item("CustomProp1").Value

i = 0
For Each oRow In oDBOM.DrawingBOMRows
	oRowDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document
	If oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value Then Continue For

	CustomPropSet = oRowDoc.PropertySets.Item("Inventor User Defined Properties")
	oDocPropValue = CustomPropSet.Item("CustomProp1").Value

	If oDocPropValue = oTargetDocPropValue Then
		Dim oBalloonValueSet As BalloonValueSet = oBalloon.BalloonValueSets.Add(oRow)
		i = 1+1
	End If
Next

If i = 0 Then MsgBox("No other balloons items found with target iProperty value",,"iLogic")


 

EESignature

0 Likes
Message 3 of 6

eric_smythC4KJK
Participant
Participant
Seems to be an issue with line 10.
(Object reference not set to an instance of an object.)

Dim oBalloon As Inventor.Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a balloon.")
If oBalloon Is Nothing Then Exit Sub

Dim oRow As DrawingBOMRow
Dim oTargetDoc As Inventor.Document
Dim oRowDoc As Inventor.Document
Dim oDBOM As DrawingBOM = oBalloon.BalloonValueSets.Item(1).ReferencedRow.Parent

For Each oRow In oDBOM.DrawingBOMRows	
	If oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value Then '(Object reference not set to an instance of an object.)	
		oTargetDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document		
	End If
Next

If oTargetDoc Is Nothing Then Exit Sub	

Dim CustomPropSet As PropertySet
oTargetDocCustomPropSet = oTargetDoc.PropertySets.Item("Inventor User Defined Properties")
oTargetDocPropValue = oTargetDocCustomPropSet.Item("CustomProp1").Value

i = 0
For Each oRow In oDBOM.DrawingBOMRows
	oRowDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document
	If oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value Then Continue For

	CustomPropSet = oRowDoc.PropertySets.Item("Inventor User Defined Properties")
	oDocPropValue = CustomPropSet.Item("CustomProp1").Value

	If oDocPropValue = oTargetDocPropValue Then
		Dim oBalloonValueSet As BalloonValueSet = oBalloon.BalloonValueSets.Add(oRow)
		i = 1+1
	End If
Next

If i = 0 Then MsgBox("No other balloons items found with target iProperty value",,"iLogic")

 

0 Likes
Message 4 of 6

eric_smythC4KJK
Participant
Participant

Does having these columns in the bom change how the code finds the values.

I am assuming that "CustomProp1" would change to my "DEG" custom property.

eric_smythC4KJK_1-1742243851603.png

 

0 Likes
Message 5 of 6

eric_smythC4KJK
Participant
Participant

I added these checks before the error

 

For Each oRow In oDBOM.DrawingBOMRows
    If oRow.BOMRow Is Nothing Then
        MsgBox("oRow.BOMRow is Nothing")
        Continue For
    End If

    If oBalloon.BalloonValueSets.Count = 0 Then
        MsgBox("No BalloonValueSets found")
        Continue For
    End If

    If oBalloon.BalloonValueSets.Item(1) Is Nothing Then
        MsgBox("oBalloon.BalloonValueSets.Item(1) is Nothing")
        Continue For
    End If

    If oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value Then
        oTargetDoc = oRow.BOMRow.ComponentDefinitions.Item(1).Document
    End If
Next

 So apparently the oRow.BOMRow is Nothing and is exiting the sub. I'm trying to understand what this line is exactly looking for.

 

oRow.BOMRow.ItemNumber = oBalloon.BalloonValueSets.Item(1).Value

is item(1),value the first level of that row? would item(2) be the next level if it were and sub assembly?

 

I also have a custom property ("tag") in the balloon itself. would that change the line of code above as well?

0 Likes
Message 6 of 6

eric_smythC4KJK
Participant
Participant

item(1) is the first item in the balloon set, item(2) is the second and so on. if so, would a value with letters and numbers come back as nothing?

0 Likes