11-16-2017
01:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-16-2017
01:00 AM
Thank you Justin so much.
This is my last version and i have to stop. The level requested is to high for me. I have tried to read your links and there are a lots of bricks between that i don't have.
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
'Set a reference to the "Structured" BOMView
Dim oBOMView As BOMView
'replace to Parts Only BOM View
oBOMView = oBOM.BOMViews.item("Parts Only")
'rename dictionary to 'Materials' and replace references to 'Colors' with 'Materials'
Dim Materials As Object
Materials = CreateObject("Scripting.Dictionary")
'replace with matching sub/function name as below (and proper arguments here)
'see above note about colors...
Call BOMweightIteration(oBOMView.BOMRows, Materials)
BOMRow.TotalQuantity()
'
' 'see above note....
' 'ensure that this spits out the proper string
' 'convert it to adding the string value to a custom iproperty instead of to a msgbox.
iProperties.Value("Custom", "PropertyName") = item & Materials(item)
End Sub
''rename to BOMweightIteration
Private Sub BOMweightIteration(oBOMRows As BOMRowsEnumerator, Materials As Object, Optional SubQty As Integer = 1)
On Error Resume Next
' Iterate through the contents of the BOM Rows.
Dim i As Long
For i = 1 To oBOMRows.count
' Get the current row.
Dim oRow As BOMRow
oRow = oBOMRows.item(i)
'Set a reference to the primary ComponentDefinition of the row
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.item(1)
'grab Materials name from comp def
'Change this if statement to a check to see if the part Materialss exists in the dictionary
If (oCompDef.Document.DocumentType = kPartDocumentObject) Then
'If it does
'add the weight of the line to the weight of the Materialss in the library
'if it doesn't
'add the weight and Materials name of the line to the dictionary
'remove face stuff as it's irrelevant
End If
'PartsOnly is flat, so remove recursion...
'Recursively iterate child rows if present.
If Not oRow.ChildRows Is Nothing Then Call BOMweightIteration(oRow.ChildRows, Materials, oRow.ItemQuantity * SubQty)
Next
End Sub