Renumbering BOM based on Parts List type

Renumbering BOM based on Parts List type

CollinWNQ4L
Participant Participant
279 Views
4 Replies
Message 1 of 5

Renumbering BOM based on Parts List type

CollinWNQ4L
Participant
Participant

So, we are using two types of Pats List for drawings: a Parts List, and an Equipment List.

The parts list is for manufactured assemblies which require all parts to be named, an equipment list is for general arrangement drawings where you just want to highlight a few systems.

The most important difference is that an Equipment List will only show Ballooned items.

 

Now I tried to write some iLogic that will recognise which Parts List is placed first (so that it always works, even when using multiple Parts Lists for whatever reason) and will renumber the BOM based on this.

 

- In case of a Parts List, it is determined simply be Title.

- But when using an Equipment List, it has to first number the items placed on the Equipment List, and then number the rest of the items based on Title.

 

Now I got it mostly working, by renumbering all parts to "X" and then numbering them according to above set rules. The only problem is I'm having is when I have an Equipment List that every second attempt to run the code will result in all numbers remaining as "X". Running it again will work fine.

 

I think this is because I first try to Renumber the Equipment list, and then SaveItemsOverrideToBOM. However, this can get an error when the BOM and Equipment List correspond. I tried to fix this by placing this part of the code in a Try/Catch instance, but it might still break because of the order?

 

Anyone able to find out what is going wrong here?

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oCurrentDoc As AssemblyDocument
oCurrentDoc = ThisDrawing.ModelDocument
Dim oBOM As BOM
oBOM = oCurrentDoc.ComponentDefinition.BOM
oBOMView = oBOM.BOMViews(2)

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



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
			
			Try
			oPLR = oPartslist.PartsListRows.Count 	'See how many items are added to the Equipment List
			oBOMCounter = oPLR + 1					'All items not in Equipment List should start at length + 1
			
			For Each oBR In oBOMView.BOMRows		'Renumber BOM to start clean
				oBR.ItemNumber = "X"
			Next oBR	
			
			oPartslist.Sort("DESCRIPTION")			'Sort Equipment List, renumber and write new numbers to 'clean' BOM
			oPartslist.Renumber				
			oPartslist.SaveItemOverridesToBOM
			oBOMView.Sort("Item", ,"Description")	'Sort BOM so that all items not numbered are sorted by description


			
			For Each oBR In oBOMView.BOMRows		'Rename all items not in Equipment List
				If oBR.ItemNumber = "X"
					oBR.ItemNumber = oBOMCounter
					oBOMCounter = oBOMCounter + 1
				End If
			Next
			Catch
			End Try
			
		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
		If oPartslist.Title = "Equipment List" Then	'Sort functions for not-primary parts lists
			oPartslist.Sort("DESCRIPTION")
		Else If oPartslist.Title = "Parts List"
			oPartslist.Sort("ITEM")
		End If
	End If
Next

 

0 Likes
Accepted solutions (1)
280 Views
4 Replies
Replies (4)
Message 2 of 5

daltonNYAW9
Advocate
Advocate
Accepted solution

If im understanding correctly...

You want the equipment items (ballooned) to be at the top of your bom (item 1, 2, 3 etc) and the rest of the parts to follow?

I rewrote your code to do that.

Firstly, I changed the 'equipment parts list' to be parts list #1, that way the subsequent parts list would already be sorted correctly

Then I added a filter to the 'equipment parts list for only Ballooned rows

Then I had it sort at the assembly file's bom, not the parts list.

Dim oDDoc As DrawingDocument = ThisDoc.Document

Dim oADoc As AssemblyDocument = ThisDrawing.ModelDocument

Dim oBOM As BOM = oADoc.ComponentDefinition.BOM

oBOM.StructuredViewEnabled = True

Dim oBOMView As BOMView = oBOM.BOMViews(2)

For Each oPartsList As PartsList In oDDoc.ActiveSheet.PartsLists
	'first parts list
	If oDDoc.Sheets(1).PartsLists.OfType(Of PartsList).ToList().IndexOf(oPartsList) = 0

		'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()
oDDoc.Update Else oPartsList.Sort("ITEM", True) End If Next

 

0 Likes
Message 3 of 5

CollinWNQ4L
Participant
Participant

It works!

 

I rewrote it again slightly because I want to be able to have a "Parts List" as main Parts List too, it just being dependent on whichever is "first".

But I basically just pasted your code in the if-statement part which determined the first Parts List is an Equipment List.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oCurrentDoc As AssemblyDocument
oCurrentDoc = ThisDrawing.ModelDocument
Dim oBOM As BOM
oBOM = oCurrentDoc.ComponentDefinition.BOM
oBOMView = oBOM.BOMViews(2)

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

Try

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
					
						If oDrawDoc.Sheets(1).PartsLists.OfType(Of PartsList).ToList().IndexOf(oPartslist) = 0
					
							'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
							oPartsList.Sort("ITEM", True)
						End If
			
		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
		If oPartslist.Title = "Equipment List" Then	'Sort functions for not-primary parts lists
			oPartslist.Sort("DESCRIPTION")
		Else If oPartslist.Title = "Parts List"
			oPartslist.Sort("ITEM")
		End If
	End If
Next

Catch
End Try
0 Likes
Message 4 of 5

daltonNYAW9
Advocate
Advocate

Get rid of the if statement:

If oDrawDoc.ActiveSheet.PartsLists.OfType(Of PartsList).ToList().IndexOf(oPartsList) = 0

 This was for finding the first parts list, and I accidently made it only work for the first sheet not the active sheet.

 

I'm slightly confused with how your code works. It constantly reorders/renumbers the parts list depending on the title. If you reorder the ballooned rows first for one parts list, then reorder it by description for another it negates what you did for the first parts list sort.

0 Likes
Message 5 of 5

CollinWNQ4L
Participant
Participant

That's because I order the second one based on Item number.

 

There are two scenarios:

- The Equipment list is first, it orders only ballooned parts and then orders the rest. The Parts List is second, but it numbers on Item, so basically it shows the Equipment List and then the rest of the items

- The Parts list is first, it orders based on Description, and then the Equipment List is sorted on Description too, but it skips everything that's not ballooned. So, there are numbers missing, but that's fine, because if it matters the Engineers should make the Equipment List the primary parts list.

 

Note that the sorting for any second list only happens in the parts list, and does not affect the BOM. So it shouldn't matter too much.

 

EDIT: Also I just noticed that basically this part

Else
		If oPartslist.Title = "Equipment List" Then	'Sort functions for not-primary parts lists
			oPartslist.Sort("DESCRIPTION")
		Else If oPartslist.Title = "Parts List"
			oPartslist.Sort("ITEM")
		End If
	End If

is redundant. It doesn't need to know what the name of any second/third/etc. parts list is, it can always just sort on ITEM