Balloon renumber

Balloon renumber

damjan_baraga
Enthusiast Enthusiast
1,940 Views
11 Replies
Message 1 of 12

Balloon renumber

damjan_baraga
Enthusiast
Enthusiast

I want to make an i-logic rule as is in the video below. Briefly, I put assembly on drawing and some parts from that assembly and then I want to renumber balloons of those parts as is item number in part list.

 

https://www.youtube.com/watch?v=AuewlPrm0VY&ab_channel=easytoolsno

 

damjan_baraga_0-1730730573437.png

 

0 Likes
Accepted solutions (1)
1,941 Views
11 Replies
Replies (11)
Message 2 of 12

damjan_baraga
Enthusiast
Enthusiast

I should add, that in case if part is not in Part list put letter X in Balloon

0 Likes
Message 3 of 12

damjan_baraga
Enthusiast
Enthusiast

I manage to make I-logic code, but its not working.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheets As Sheets
Dim oSheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets
oViews = oSheet.DrawingViews
For Each oView In oViews
If oView.ViewType <> 10504 Then ' Not kProjectedDrawingViewType
' Get the full filename of the view model
Dim oModelFileName As String
oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName

Dim oPartList As PartsList
' Try to get the parts list from the table of this sheet
Try
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)

Catch ' On error, try and search all sheets for the first found parts list
' Iterate through each sheet
Dim i As Long
For i = 1 To oDrawDoc.Sheets.Count
If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
Next
If oSheet.PartsLists.Count = 0 Then
MessageBox.Show("No Parts List found in the drawing.")
Exit Sub
End If

oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
End Try

' Iterate through the contents of the parts list.
Dim oRow As PartsListRow
Dim oRowFileName As String

Dim j As Long
For j = 1 To oPartList.PartsListRows.Count
' Get the current row
oRow = oPartList.PartsListRows.Item(j)
' Get filename of model in row
oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName

' Compare the filenames
If StrComp(oModelFileName, oRowFileName, CompareMethod.Text) = 0 Then
' Get the value of Item from the Parts List (first item in the row)
Dim oItemValue As String
oItemValue = oRow.Item(1).Value

' Iterate through all the balloons in the sheet
Dim oBalloons As Balloons
Dim oBalloon As Balloon
oBalloons = oSheet.Balloons
For Each oBalloon In oBalloons
' Access the component that the balloon is attached to
Dim oBalloonComponent As ComponentOccurrence
oBalloonComponent = oBalloon.ReferencedComponent

' If the balloon is attached to the correct component, update the balloon text
If Not oBalloonComponent Is Nothing Then
If StrComp(oBalloonComponent.Definition.Document.FullFileName, oModelFileName, CompareMethod.Text) = 0 Then
' Set the balloon text to the item number (part number)
oBalloon.Text = oItemValue
End If
End If
Next
End If
Next
End If
Next
Next

MessageBox.Show("Balloon renumbering finished!")

0 Likes
Message 4 of 12

chicco199
Explorer
Explorer
0 Likes
Message 5 of 12

damjan_baraga
Enthusiast
Enthusiast

Thanks for the suggestion. I already tried it, but this code is not working even with a lot of modifications.   

0 Likes
Message 6 of 12

chicco199
Explorer
Explorer

You can go around the corner and create a new user value that will match the values ​​from the main assembly. You can copy the values ​​either in the specification or Ilogic.
Sorry for my language.

0 Likes
Message 7 of 12

jnowel
Collaborator
Collaborator
Accepted solution

I've edited your code a bit to make it work (though haven't tested it intensively)
I think the oView For-Loop is unnecessary, so had it removed.

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Inventor.Sheet
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets

	Dim oPartList As PartsList
	' Try to get the parts list from the table of this sheet
	Try
		oPartList = oSheet.PartsLists.Item(1)
	Catch ' On error, try and search all sheets for the first found parts list
		' Iterate through each sheet
		Dim i As Long
		For i = 1 To oDrawDoc.Sheets.Count
			If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
		Next
	
		If oSheet.PartsLists.Count = 0 Then
			MessageBox.Show("No Parts List found in the drawing.")
			Exit Sub
		End If
		oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
	End Try


	Dim oBalloon As Balloon
	
	For Each oBalloon In oSheet.Balloons
		
		' Iterate through the contents of the parts list.
		Dim oRow As PartsListRow
		Dim oRowFileName As String
		
		Dim j As Long
			For j = 1 To oPartList.PartsListRows.Count
				
			' Get the current row
			oRow = oPartList.PartsListRows.Item(j)

			'Iterate and Get filename of model in row
			'iterating component definitions in case you have a 'merged' row
			For Each oCompDef As ComponentDefinition In oRow.ReferencedRows(1).BOMRow.ComponentDefinitions
				
				'Used "FullDocumentName" instead of "FullFileName" to handle components with Model states
				'if "FullFileName" is used, then you can't differentiate if you used the same component with different model states in your assy
				oRowFileName = oCompDef.Document.FullDocumentName
				
				' Get the value of Item from the Parts List (first item in the row)
				Dim oItemValue As String
				oItemValue = oRow.Item(1).Value
			
				Dim oBalloonComponent As DocumentDescriptor
				oBalloonComponent = oBalloon.ParentView.ReferencedDocumentDescriptor
				
				' If the balloon is attached to the correct component, update the balloon text
				'Balloon override only works on if the Balloon.ParentView is a Component of PartsList Referened Document
				If StrComp(oBalloonComponent.FullDocumentName, oRowFileName, CompareMethod.Text) = 0 Then
					If oBalloon.BalloonValueSets(1).OverrideValue <> oBalloon.BalloonValueSets(1).ItemNumber Then
						oBalloon.BalloonValueSets(1).OverrideValue = oItemValue
					End If								
				End If
			Next
		Next
	Next
Next

MessageBox.Show("Balloon renumbering finished!")





0 Likes
Message 8 of 12

damjan_baraga
Enthusiast
Enthusiast

So far, It`s works. Now I must figure out how to put X in Balloons, which are not in Part list 

0 Likes
Message 9 of 12

jnowel
Collaborator
Collaborator

You can just check the balloon's parent view document then compare it with the parts list's document.
added another boolean variable bIsInPartsList and some lines 

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Inventor.Sheet
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets

	Dim oPartList As PartsList
	' Try to get the parts list from the table of this sheet
	Try
		oPartList = oSheet.PartsLists.Item(1)
	Catch ' On error, try and search all sheets for the first found parts list
		' Iterate through each sheet
		Dim i As Long
		For i = 1 To oDrawDoc.Sheets.Count
			If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
		Next
	
		If oSheet.PartsLists.Count = 0 Then
			MessageBox.Show("No Parts List found in the drawing.")
			Exit Sub
		End If
		oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
	End Try


	Dim oBalloon As Balloon
	
	For Each oBalloon In oSheet.Balloons
		
		' Iterate through the contents of the parts list.
		Dim oRow As PartsListRow
		Dim oRowFileName As String
		
		Dim bIsInPartsList As Boolean = False
		
		If oBalloon.ParentView.ReferencedDocumentDescriptor.FullDocumentName = oPartList.ReferencedDocumentDescriptor.FullDocumentName Then
			'these are for balloons attached to the view of the main parts list
			bIsInPartsList = True
		End If
		
		Dim j As Long
			For j = 1 To oPartList.PartsListRows.Count
				
			' Get the current row
			oRow = oPartList.PartsListRows.Item(j)

			'Iterate and Get filename of model in row
			'iterating component definitions in case you have a 'merged' row
			For Each oCompDef As ComponentDefinition In oRow.ReferencedRows(1).BOMRow.ComponentDefinitions
				
				'Used "FullDocumentName" instead of "FullFileName" to handle components with Model states
				'if "FullFileName" is used, then you can't differentiate if you used the same component with different model states in your assy
				oRowFileName = oCompDef.Document.FullDocumentName
				
				' Get the value of Item from the Parts List (first item in the row)
				Dim oItemValue As String
				oItemValue = oRow.Item(1).Value
			
				Dim oBalloonComponent As DocumentDescriptor
				oBalloonComponent = oBalloon.ParentView.ReferencedDocumentDescriptor
				
				' If the balloon is attached to the correct component, update the balloon text
				'Balloon override only works on if the Balloon.ParentView is a Component of PartsList Referened Document
				If StrComp(oBalloonComponent.FullDocumentName, oRowFileName, CompareMethod.Text) = 0 Then
					bIsInPartsList = True
					If oBalloon.BalloonValueSets(1).OverrideValue <> oBalloon.BalloonValueSets(1).ItemNumber Then
						oBalloon.BalloonValueSets(1).OverrideValue = oItemValue
					End If								
				End If
			Next
		Next
		
		If Not bIsInPartsList Then
			oBalloon.BalloonValueSets(1).OverrideValue = "X"
		End If
		
	Next
Next

MessageBox.Show("Balloon renumbering finished!")



 

0 Likes
Message 10 of 12

damjan_baraga
Enthusiast
Enthusiast

Something strange is happening. If is Item same number as should be renumbered, thet renumbering is not done. In the picture you can see pos 8 from Part list. That should be overridden with 8 but stay 1.

 

damjan_baraga_0-1730959838901.png

 

0 Likes
Message 11 of 12

jnowel
Collaborator
Collaborator

try changing the if statement  (line 60-62) to this:

 

If oBalloon.BalloonValueSets(1).ItemNumber <> oItemValue Then
	oBalloon.BalloonValueSets(1).OverrideValue = oItemValue
End If	

 

 

0 Likes
Message 12 of 12

damjan_baraga
Enthusiast
Enthusiast

Here is whole working code. jnowel, Thank`s

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Inventor.Sheet
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets

	Dim oPartList As PartsList
	' Try to get the parts list from the table of this sheet
	Try
		oPartList = oSheet.PartsLists.Item(1)
	Catch ' On error, try and search all sheets for the first found parts list
		' Iterate through each sheet
		Dim i As Long
		For i = 1 To oDrawDoc.Sheets.Count
			If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
		Next
	
		If oSheet.PartsLists.Count = 0 Then
			MessageBox.Show("No Parts List found in the drawing.")
			Exit Sub
		End If
		oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
	End Try


	Dim oBalloon As Balloon
	
	For Each oBalloon In oSheet.Balloons
		
		' Iterate through the contents of the parts list.
		Dim oRow As PartsListRow
		Dim oRowFileName As String
		
		Dim bIsInPartsList As Boolean = False
		
		If oBalloon.ParentView.ReferencedDocumentDescriptor.FullDocumentName = oPartList.ReferencedDocumentDescriptor.FullDocumentName Then
			'these are for balloons attached to the view of the main parts list
			bIsInPartsList = True
		End If
		
		Dim j As Long
			For j = 1 To oPartList.PartsListRows.Count
				
			' Get the current row
			oRow = oPartList.PartsListRows.Item(j)

			'Iterate and Get filename of model in row
			'iterating component definitions in case you have a 'merged' row
			For Each oCompDef As ComponentDefinition In oRow.ReferencedRows(1).BOMRow.ComponentDefinitions
				
				'Used "FullDocumentName" instead of "FullFileName" to handle components with Model states
				'if "FullFileName" is used, then you can't differentiate if you used the same component with different model states in your assy
				oRowFileName = oCompDef.Document.FullDocumentName
				
				' Get the value of Item from the Parts List (first item in the row)
				Dim oItemValue As String
				oItemValue = oRow.Item(1).Value
			
				Dim oBalloonComponent As DocumentDescriptor
				oBalloonComponent = oBalloon.ParentView.ReferencedDocumentDescriptor
				
				' If the balloon is attached to the correct component, update the balloon text
				'Balloon override only works on if the Balloon.ParentView is a Component of PartsList Referened Document
				If StrComp(oBalloonComponent.FullDocumentName, oRowFileName, CompareMethod.Text) = 0 Then
					bIsInPartsList = True
				   oBalloon.BalloonValueSets(1).OverrideValue = oItemValue
				End If
			Next
		Next
		' If the balloon is not a Component of PartsList Referened Document 
								
		If Not bIsInPartsList Then
			oBalloon.BalloonValueSets(1).OverrideValue = "X"
		End If
		
	Next
Next

'MessageBox.Show("Balloon renumbering finished!")

 

0 Likes