- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
i don't know where to start...
At assembly level, would like to write a rule that write a unique Custom iProp (at assembly level) that contain:
all the materials involved in that assembly and the total weight for each material. Es
My Custom iProp = Steel Mild 203 Kg, Iron 2000 kg, Aluminum 340 Kg.
is there any chance to reach this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sure. I would probably iterate through all rows in the structured BOM and check the material/mass and add the running total into a 2d array as you iterate through the BOM.
But can't you just create a Parts Only parts list on a drawing and FILTER/GROUP by material to get the results you want?
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is an iLogic script I made to count the surface area of colors on parts in an assembly. If you replace the color with material and surface area with weight this script should work for you. I don't have time to tweak this now, but if you need help someone could probably help out before I get time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi , thank you for the asnwer!
This is what we want:
You are right, at the moment we have another part list style, but we would like to obtain that above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I commented and bolded the things you need to change so that you can get some solid practice learning it for yourself in the case that you don't luck out and get a freebie by someone else doing it for you (or decide to pay for someone to do it otherwise).
Let us know if you get caught on anything and we can help from there.
The logical flow is all done, so you just need to convert it to code.
Good luck
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 Colors As Object
Colors = CreateObject("Scripting.Dictionary")
'replace with matching sub/function name as below (and proper arguments here)
'see above note about colors...
Call PaintRecurse(oBOMView.BOMRows, Colors)
'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 Colors
msg = "Paint: " & item & " Area: " & Colors(item) & " cm^2" & Iif(msg <> "",vbCrLf & msg,"")
Next
MsgBox(msg)
End Sub
'rename to BOMweightIteration
Private Sub PaintRecurse(oBOMRows As BOMRowsEnumerator, Colors 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 PaintRecurse(oRow.ChildRows, Colors, oRow.ItemQuantity * SubQty)
Next
End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
.
Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Facebook | Twitter | Youtube
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Now i have improved a little.
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)
'
' '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 & " Area: " & Materials(item) & Iif(msg <> "",vbCrLf & msg,"")
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 Materialss 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 Materialss 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
gettin this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yup! Looks pretty good. Your helper function there still needs completing.
Here's a couple links to help.
'Mass iProperty.
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-ABA1FF89-A0EB-4D21-AC49-5A69D321410C
'Note: You likely need to do a mass * total quantity, so here is a link to get total quantity from BOM:
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-D475FABC-33CE-4F0D-B15C-C92805BB23A7
'Also, dictionaries have a .Contains method (make sure you switch the samples to vb).
Below is the code cleaned up with comments removed of the stuff that's done so it's easier to read. Comments should be "why", and not a "how/what" for every line. The code tells you that in the language. It's redundant and messy to have it in 2 languages.
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.item("Parts Only")
Dim Materials As Object
Materials = CreateObject("Scripting.Dictionary")
Call BOMweightIteration(oBOMView.BOMRows, Materials)
For Each item In Materials
msg = "Materials: " & item & " Area: " & Materials(item) & Iif(msg <> "",vbCrLf & msg,"")
Next
MsgBox(msg)
End Sub
Private Sub BOMweightIteration(oBOMRows As BOMRowsEnumerator, Materials As Object, Optional SubQty As Integer = 1)
On Error Resume Next
Dim i As Long
For i = 1 To oBOMRows.count
Dim oRow As BOMRow
oRow = oBOMRows.item(i)
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.item(1)
'grab Materialss name from comp def
'Change this if statement to a check to see if the part Materialss exists in the dictionary
'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 Materialss name of the line to the dictionary
'remove face stuff as it's irrelevant
End If
Next
End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Seems like you've put in a good effort.
As it is below, it assumes that there are no Inseparable BOM Structure assemblies as the method to grab the weight for it fails.
Even for an "experienced" programmer like me, this still took me about half an hour to piece together, excluding what I had written before.
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")
Dim Materials As Object
Materials = CreateObject("Scripting.Dictionary")
Call BOMweightIteration(oBOMView.BOMRows, Materials)
For Each item In Materials
If msg = "" Then
'msg = "Materials & Mass:" & item & " " & Materials(item) & "kg" & ", "
msg = item & " " & Materials(item) & "kg" & ", "
Else
msg = msg & item & " " & Materials(item) & "kg" & ","
End If
Next
msg = Left(msg, Len(msg) - 1) 'removes the last comma
Materials = Nothing
'iProperties.Value(System.IO.Path.GetFileName(oDoc.FullFilename), "Custom", "MatlWeights") = msg
iProperties.Value("Custom", "MatlWeights") = msg
MsgBox(msg)
End Sub
Private Sub BOMweightIteration(oBOMRows As BOMRowsEnumerator, ByRef Materials As Object)
Dim i As Long
Dim oItemWeight As Double
Dim weight As Double
For i = 1 To oBOMRows.count
Dim oRow As BOMRow
oRow = oBOMRows.Item(i)
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)
oRowDoc = oCompDef.Document
Matl = oRowDoc.PropertySets("Design Tracking Properties")("Material").Value
Weight = oCompDef.MassProperties.Mass 'mass in kg as it is database units
oItemWeight = Round(Weight*oRow.TotalQuantity, 2)
'MsgBox(oRowDoc.FullFileName & vbLf & Matl & vbLf & oItemWeight)
If Materials.Exists(Matl) Then
Materials(Matl) = Materials(Matl) + oItemWeight 'where 1 = 1 decimal place
Else
Materials.Add(Matl, oItemWeight)
End If
Next
End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you, again, Justin.
You have push me to a direction, and i have learned a "logic" in this, step by step.
Therare a lots more to learn, but it's a very flexible tool this iLogic.
Thank you for the support, post after post and thank you for break the wall i have found at the end of my learning path.
I will try this, but i have already see that it works great, i have just to study line, after line, if a collegue will ask me a variation.
Thank youJustin and thank you the first guy too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It works great wow
I am embarassed to be here again for a so small detail.
The code generatea comma after some material.
I have tried to act in the strings, but with no success.
I suspect that these are the area where i can act, but i am not sure.
For example, maybe, even if i will try all the possibile, there no such a possibility because the comma comes from the BOM, or froma cycle of the code, i don't know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Mhm.
If you look at the material names, you will see that comma exists there already. The only comma that is added in MY CODE is the one right after the 'kg'.
You have 3 options forward:
1. Change the comma that is in the code, added before 'kg' to a different symbol to make it readable (ie; a ';', or a '-' would probably work.
2. MODIFY the material name when you accessing it with the code.
- Depending on HOW you want to modify it you have various options.
Option a: Reorder the name by moving everything behind the comma to the start of the string (ie; 'Steel, Mild' becomes 'Mild Steel')
Option b: Replace the comma in the material name to another character (ie; 'Steel, Mild' to 'Steel [Mild]')
Option c: WRITE the code to do a wholesale swap using a Select Case (ie; 'Steel, Mild' to '44W')
If you go through option 2, you have 2 efficient options for where you want to access the MATERIAL NAME to change the commas:
Either BEFORE putting in in the dictionary, or WHEN you fetch it from the dictionary.
3. Modify material names in your library so that the material names appear how you want them to in the BOM / Output.
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Great!
Very clear.
I will apply mysekf to this!
Thank you Justin for your time and kindness!
![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
Do you have any idea why this rule work fine with Inventor in English and i get this error if I use another language Inventor release?
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")
Dim Materials As Object
Materials = CreateObject("Scripting.Dictionary")
Call BOMweightIteration(oBOMView.BOMRows, Materials)
For Each item In Materials
If msg = "" Then
'msg = "Materials & Mass:" & item & " " & Materials(item) & "kg" & ", "
msg = item & " " & Materials(item) & "kg" & ", "
Else
msg = msg & item & " " & Materials(item) & "kg" & ","
End If
Next
msg = Left(msg, Len(msg) - 1) 'rimuove l'ultima virgola
Materials = Nothing
'iProperties.Value(System.IO.Path.GetFileName(oDoc.FullFilename), "Custom", "MatlWeights") = msg
iProperties.Value("Custom", "MatlWeights") = msg
MsgBox(msg)
End Sub
Private Sub BOMweightIteration(oBOMRows As BOMRowsEnumerator, ByRef Materials As Object)
Dim i As Long
Dim oItemWeight As Double
Dim weight As Double
For i = 1 To oBOMRows.count
Dim oRow As BOMRow
oRow = oBOMRows.Item(i)
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)
oRowDoc = oCompDef.Document
Matl = oRowDoc.PropertySets("Design Tracking Properties")("Material").Value
Weight = oCompDef.MassProperties.Mass 'massa in kg come l'unità del database
oItemWeight = Round(Weight*oRow.TotalQuantity, 2)
'MsgBox(oRowDoc.FullFileName & vbLf & Matl & vbLf & oItemWeight)
If Materials.Exists(Matl) Then
Materials(Matl) = Materials(Matl) + oItemWeight 'dove 1 = 1 posizione decimale
Else
Materials.Add(Matl, oItemWeight)
End If
Next
End Sub