iLogic to sort BOM based on Model Tree order

iLogic to sort BOM based on Model Tree order

CollinWNQ4L
Participant Participant
381 Views
0 Replies
Message 1 of 1

iLogic to sort BOM based on Model Tree order

CollinWNQ4L
Participant
Participant

So a while back I made a piece of iLogic code that will sort the BOM automatically.

 

Basically, this was important for our company because a lot of times, we will use an "Equipment List" on drawings, which shows only ballooned items. My code would sort the ballooned components (shown in the Equipment List), renumber them, write the renumbered items to the BOM and then renumber the rest of the items that are not shown in the Equipment List.

 

The only ceveat of this was that up until now we had a standard set-up with sub-assemblies, which were named. The ballooned components exist within subassemblies. However, the Equipment List would sort names, but take the name of the parent assembly into account.

 

Say for example you had ( (B) = Ballooned item)

 

0001 - Main steel

Beam 1 (B)

Eye 1 (B)

Socket 1 (B)

0002 - Secondary Steel

Beam 2 (B)

Eye 2

Socket 2 (B)

 

The Equipment List would show:

1. Beam 1

2. Eye 1

3. Socket 1

4. Beam 2

5. Socket 2

 

But now, the ballooned items were showing the wrong descriptions and names, because they would use the Assembly above. We could "Unfold" the assembly in the parts list, but this, in my opinion, was not the correct way and we would need to use "Phantom assemblies". But now the Equipment list would show:

 

1. Beam 1

2. Beam 2

3. Eye 1

4. Socket 1

5. Socket 2

 

Obviously, this is because it is now sorted alphabatically and no longer takes into account it's parent assembly.

 

I think a simpler way to achieve what I would like to have, is if I could sort based on the order of the model tree. That way engineers can be made responsible for the build up of their models, but our base projects would have this set-up correctly, where parts in an assembly are "Next in line" from their parent assemblies.

 

Does anyone know how to achieve this?

 

This was my code so far, which sorts the Ballooned Items first if it's an Equipment List by name and then sorts the rest. If it's a part list, it just sorts on name:

Sub main
	
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument	
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim oPartslist As PartsList

Try 
	oPartslist = oSheet.PartsLists(1)
Catch
	Exit Sub
End Try

	If ThisDrawing.ModelDocument Is Nothing Then
		Exit Sub
	Else 
		If ThisDrawing.ModelDocument.DocumentType = kAssemblyDocumentObject
			AutoUpdate()
		Else
			Exit Sub
		End If
	End If
End Sub


Sub AutoUpdate()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oCurrentDoc As AssemblyDocument
oCurrentDoc = ThisDrawing.ModelDocument
Dim oBOM As BOM

Dim oListCheck = 0 'Variable that will keep track of how many parts lists there are

Try

oBOM = oCurrentDoc.ComponentDefinition.BOM
oBOMView = oBOM.BOMViews(2)

For Each oPartslist As Inventor.PartsList In oDrawDoc.ActiveSheet.PartsLists
	oListCheck = oListCheck + 1 'Another Parts List
	
	
	If oListCheck = 1 'Only the first PartsList should renumber the BOM
		If oPartslist.Title = "Equipment List" Then
			
					oBOM.StructuredViewEnabled = True
					
					
							'remove filters
							For Each oPartsListFilterItem As PartsListFilterItem In oPartslist.FilterSettings
								oPartsListFilterItem.Delete
							Next
							oPartslist.FilterSettings.Enabled = True
					
							'create object collection of sorted rows
							Dim sortedRows As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
					
							'loop through each row to add to sorted rows
							For Each oPartsListRow As PartsListRow In oPartslist.PartsListRows
								If oPartsListRow.Ballooned = True
									'do nothing
								Else
									sortedRows.Add(oPartsListRow.ReferencedRows(1).BOMRow)
								End If
							Next
					
							'filter parts list
							oPartslist.FilterSettings.Add(PartsListFilterItemTypeEnum.kBalloonedItemsOnlyFilterItem)
					
							oPartslist.Sort("DESCRIPTION", True)
					
							oPartslist.Renumber()
							
							'doesnt work if no change
							Try
								oPartslist.SaveItemOverridesToBOM
							Catch : End Try
							
							'renumber at assembly level
							oBOMView.Renumber(oPartslist.PartsListRows.Count + 1, 1, sortedRows)
							oBOMView.Sort("Item")
							oBOMView.Renumber()
					                oDrawDoc.Update
			
		Else If oPartslist.Title = "Parts List"		'When using a Parts List, simply renumber BOM based on Title
			oBOMView.Sort("Description")
			oBOMView.Renumber(1,1)
			oPartslist.Sort("ITEM")					'Sort Parts list by newly numbered BOM
		End If
	
	
	Else
			oPartslist.Sort("ITEM")
	End If
Next

Catch
End Try
End Sub

 

0 Likes
382 Views
0 Replies
Replies (0)