11-15-2017
10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-15-2017
10:17 AM
Hi Justin.
Am i in the right direction?
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
'remove structured view stuff
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
'Set a reference to the "Structured" BOMView
Dim oBOMView As BOMView
'replace to Parts Only BOM View
oBOMView = oBOM.BOMViews.item("Structured")
'rename dictionary to 'Materials' and replace references to 'Colors' with 'Materials'
Dim Materials As Object
Materials = CreateObject("Scripting.Materials")
'replace with matching sub/function name as below (and proper arguments here)
'see above note about colors...
Call BOMweightIteration(oBOMView.BOMRows, Materials)
'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.
For Each item In Materials
msg = "Materials: " & item & Materials(item)
Next
MsgBox(msg)
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 material name from comp def
'Change this if statement to a check to see if the part material exists in the dictionary
If (oCompDef.Document.DocumentType = kPartDocumentObject) Then
'If it does
'add the weight of the line to the weight of the material in the library
'if it doesn't
'add the weight and material name of the line to the dictionary
' 'remove face stuff as it's irrelevant
' Dim oFaces As Faces
' oFaces = oCompDef.SurfaceBodies(1).Faces
'
' Dim oFace As Face
' For Each oFace In oFaces
' Colors(oFace.Appearance.DisplayName) = Colors(oFace.Appearance.DisplayName) + oFace.Evaluator.Area * oRow.ItemQuantity * SubQty
' Next
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, Colors, oRow.ItemQuantity * SubQty)
Next
End Sub
I have an an error about impossible to create component ACtive X.
I see it quite difficult.