Iterate through a BOM and display a quantity for every part

Iterate through a BOM and display a quantity for every part

Anonymous
Not applicable
994 Views
1 Reply
Message 1 of 2

Iterate through a BOM and display a quantity for every part

Anonymous
Not applicable

Hi all,

 

I am trying to write a rule to iterate through a BOM and have the quantity for every part be displayed. So far I have:

	part_number = iProperties.Value("Project", "Part Number")
	pnstr = CStr(part_number)
	quantity = ThisBOM.CalculateQuantity("Model Data", pnstr)
	MessageBox.Show(quantity, "Title")

How can Make this run through and display a quantity value for every part in an assembly?

0 Likes
Accepted solutions (1)
995 Views
1 Reply
Reply (1)
Message 2 of 2

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

CalculateQuantity sets the quantity of a BOM row from overridden back to automatic calculation. For parts code below could help. If you need quantities of assemblies too, there's much more work to do.

 

If Not ThisDoc.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule is for assembly documents",, "iLogic")
	Exit Sub
End If

Dim oAssDoc As AssemblyDocument = ThisDoc.Document

Dim oBom As BOM = oAssDoc.ComponentDefinition.BOM
oBom.PartsOnlyViewEnabled = True

Dim oBomView As BOMView
For Each oBomView In oBom.BOMViews
	If oBomView.Name = "Parts only" Then Exit For
Next

If oBomView Is Nothing Then
	MsgBox("Can not access BOM view",, "iLogic")
	Exit Sub
End If

Dim oBomRow As BOMRow
Dim lQuantity As Long
Dim sPartNumber As String

For Each oBomrow In oBomView.BOMRows
	lQuantity = oBomRow.ItemQuantity 	
	sPartNumber = oBomRow.ComponentDefinitions(1).Document.propertysets(3).item(2).value
	MsgBox("PNr: " & sPartNumber & vbCrLf & "Qty: " & lQuantity,, "iLogic")
Next

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com