<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: iLogic write custom iprop t assembly level in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547011#M76890</link>
    <description>&lt;P&gt;.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2017 18:12:32 GMT</pubDate>
    <dc:creator>admaiora</dc:creator>
    <dc:date>2017-11-15T18:12:32Z</dc:date>
    <item>
      <title>iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7545702#M76866</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i don't know where to start...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At assembly level, would like to write a rule that write a unique Custom iProp (at assembly level) that contain:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the materials involved in that assembly and the total weight for each material. Es&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Custom iProp = Steel Mild 203 Kg, Iron 2000 kg, Aluminum 340 Kg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there any chance to reach this?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 11:24:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7545702#M76866</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T11:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546171#M76874</link>
      <description>&lt;P&gt;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&amp;nbsp;BOM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 14:12:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546171#M76874</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-11-15T14:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546339#M76876</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-forum/how-do-i-get-inventor-to-calculate-and-sum-up-painted-faces-in/m-p/6565113#M613487" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-forum/how-do-i-get-inventor-to-calculate-and-sum-up-painted-faces-in/m-p/6565113#M613487&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 14:49:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546339#M76876</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2017-11-15T14:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546684#M76884</link>
      <description>&lt;P&gt;Hi , thank you for the asnwer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what we want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dc.png" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/426282i67F43D2A19154106/image-size/large?v=v2&amp;amp;px=999" role="button" title="dc.png" alt="dc.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right, at the moment we have another part list style, but we would like to obtain that above.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:06:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546684#M76884</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T16:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546690#M76885</link>
      <description>&lt;P&gt;Hi, thank you friend!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not an expert (total) of iLogic, but i will apply myself to it. i will try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:07:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546690#M76885</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T16:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546708#M76886</link>
      <description>&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;nope...it' a too difficult level what you wrote.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:15:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546708#M76886</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T16:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546853#M76887</link>
      <description>&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us know if you get caught on anything and we can help from there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logical flow is all done, so you just need to convert it to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Sub Main
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    oBOM = oDoc.ComponentDefinition.BOM
    &lt;BR /&gt;&lt;STRONG&gt;'remove structured view stuff&lt;/STRONG&gt;
    oBOM.StructuredViewFirstLevelOnly = False
    oBOM.StructuredViewEnabled = True

    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView&lt;BR /&gt;&lt;STRONG&gt;'replace to Parts Only BOM View&lt;/STRONG&gt;
    oBOMView = oBOM.BOMViews.item("Structured")
    &lt;BR /&gt;    &lt;STRONG&gt;'rename dictionary to 'Materials' and replace references to 'Colors' with 'Materials'&lt;/STRONG&gt;
    Dim Colors As Object
    Colors = CreateObject("Scripting.Dictionary")
    &lt;BR /&gt;    &lt;STRONG&gt;'replace with matching sub/function name as below (and proper arguments here)&lt;BR /&gt;    'see above note about colors...&lt;/STRONG&gt;
    Call PaintRecurse(oBOMView.BOMRows, Colors)
    &lt;BR /&gt;&lt;STRONG&gt;    'see above note....&lt;BR /&gt;    'ensure that this spits out the proper string&lt;BR /&gt;    'convert it to adding the string value to a custom iproperty instead of to a msgbox.&lt;/STRONG&gt;
    For Each item In Colors
        msg = "Paint: " &amp;amp; item &amp;amp; " Area: " &amp;amp; Colors(item) &amp;amp; " cm^2" &amp;amp; Iif(msg &amp;lt;&amp;gt; "",vbCrLf &amp;amp; msg,"")
    Next
	
    MsgBox(msg)

End Sub
&lt;BR /&gt;&lt;STRONG&gt;'rename to BOMweightIteration&lt;/STRONG&gt;
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)
        &lt;BR /&gt;        &lt;STRONG&gt;'grab material name from comp def&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;STRONG&gt;        'Change this if statement to a check to see if the part material exists in the dictionary&lt;/STRONG&gt;
        If (oCompDef.Document.DocumentType = kPartDocumentObject) Then&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;        'If it does&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;              'add the weight of the line to the weight of the material in the library&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;        'if it doesn't&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;              'add the weight and material name of the line to the dictionary&lt;/STRONG&gt;&lt;BR /&gt;         &lt;BR /&gt;&lt;BR /&gt;            &lt;STRONG&gt;'remove face stuff as it's irrelevant&lt;/STRONG&gt;
            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
&lt;BR /&gt; &lt;STRONG&gt;       'PartsOnly is flat, so remove recursion...&lt;/STRONG&gt;
        'Recursively iterate child rows if present.
        If Not oRow.ChildRows Is Nothing Then Call PaintRecurse(oRow.ChildRows, Colors, oRow.ItemQuantity * SubQty)
    Next
End Sub&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 17:07:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7546853#M76887</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-11-15T17:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547011#M76890</link>
      <description>&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 18:12:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547011#M76890</guid>
      <dc:creator>admaiora</dc:creator>
      <dc:date>2017-11-15T18:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547085#M76891</link>
      <description>&lt;P&gt;Hi Justin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am i in the right direction?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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: " &amp;amp; item  &amp;amp; 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 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an an error about impossible to create component ACtive X.&lt;/P&gt;&lt;P&gt;I see it quite difficult.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 18:17:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547085#M76891</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T18:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547274#M76892</link>
      <description>&lt;P&gt;Now i have improved a little.&lt;/P&gt;&lt;PRE&gt;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: " &amp;amp; item &amp;amp; " Area: " &amp;amp; Materials(item) &amp;amp;  Iif(msg &amp;lt;&amp;gt; "",vbCrLf &amp;amp; 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 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gettin this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ed.jpg" style="width: 444px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/426728i888E58E12F9D87AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="ed.jpg" alt="ed.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 19:12:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547274#M76892</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-15T19:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547908#M76906</link>
      <description>&lt;P&gt;Yup! Looks pretty good. Your helper function there still needs completing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a couple links to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Mass iProperty.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-ABA1FF89-A0EB-4D21-AC49-5A69D321410C" target="_blank"&gt;http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-ABA1FF89-A0EB-4D21-AC49-5A69D321410C&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Note: You likely need to do a mass * total quantity, so here is a link to get total quantity from BOM:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-D475FABC-33CE-4F0D-B15C-C92805BB23A7" target="_blank"&gt;http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-D475FABC-33CE-4F0D-B15C-C92805BB23A7&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Also, dictionaries have a .Contains method (make sure you switch the samples to vb).&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/kw5aaea4(v=vs.110).aspx?cs-save-lang=1&amp;amp;cs-lang=vb#code-snippet-3" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/kw5aaea4(v=vs.110).aspx?cs-save-lang=1&amp;amp;cs-lang=vb#code-snippet-3&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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: " &amp;amp; item &amp;amp; " Area: " &amp;amp; Materials(item) &amp;amp;  Iif(msg &amp;lt;&amp;gt; "",vbCrLf &amp;amp; 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 &lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Nov 2017 22:45:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7547908#M76906</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-11-15T22:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7548795#M76912</link>
      <description>&lt;P&gt;Thank you Justin so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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 &amp;amp;  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 &lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Nov 2017 09:00:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7548795#M76912</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-16T09:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7551822#M76947</link>
      <description>&lt;P&gt;Seems like you've put in a good effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As it is below, it&amp;nbsp;assumes that there are no Inseparable BOM Structure assemblies as the method to grab the weight for it fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even for an "experienced" programmer like me, this still took me about half an hour to piece together,&amp;nbsp;excluding what I had written before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 &amp;amp; Mass:" &amp;amp; item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ", "
			msg = item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ", "
		Else
        	msg = msg &amp;amp; item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ","
		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 &amp;amp; vbLf &amp;amp; Matl &amp;amp; vbLf &amp;amp; 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 &lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 05:02:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7551822#M76947</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-11-17T05:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7552207#M76955</link>
      <description>&lt;P&gt;Thank you, again, Justin.&lt;/P&gt;&lt;P&gt;You have push me to a direction, and i have learned a "logic" in this, step by step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therare a lots more to learn, but it's a very flexible tool this iLogic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank youJustin and thank you the first guy too.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:04:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7552207#M76955</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-17T09:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7552300#M76957</link>
      <description>&lt;P&gt;It works great wow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am embarassed to be here again for a so small detail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fg.jpg" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/427525i60EDE29FC1D32696/image-size/large?v=v2&amp;amp;px=999" role="button" title="fg.jpg" alt="fg.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code generatea comma after some material.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to act in the strings, but with no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that these are the area where i can act, but i am not sure.&lt;/P&gt;&lt;P&gt;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,&amp;nbsp; i don't know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gf.jpg" style="width: 598px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/427527iF0B2622A88FFEDE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="gf.jpg" alt="gf.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:37:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7552300#M76957</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-17T09:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7553011#M76970</link>
      <description>&lt;P&gt;Mhm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have&amp;nbsp;3 options forward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. MODIFY the material name when you accessing it with the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - Depending on HOW you want to modify it you have various options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Option a: Reorder the name by moving everything behind the comma to the start of the string (ie; 'Steel, Mild' becomes 'Mild Steel')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Option b: Replace the comma in the material name to another character (ie; 'Steel, Mild' to 'Steel [Mild]')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Option c: WRITE the code to do a wholesale swap using a Select Case (ie; 'Steel, Mild' to '44W')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If you go through option 2, you have 2 efficient options for where you want to access the MATERIAL NAME to change the commas:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Either BEFORE putting in in the dictionary, or WHEN you fetch it from the dictionary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Modify material names in your library so that the material names appear how you want them to in the BOM / Output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:12:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7553011#M76970</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-11-17T14:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7553134#M76976</link>
      <description>&lt;P&gt;Great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will apply mysekf to this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you Justin for your time and&amp;nbsp; kindness!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:49:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/7553134#M76976</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2017-11-17T14:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic write custom iprop t assembly level</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/10417149#M125759</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;amp; Mass:" &amp;amp; item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ", "
			msg = item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ", "
		Else
        	msg = msg &amp;amp; item &amp;amp; " " &amp;amp; Materials(item) &amp;amp; "kg" &amp;amp; ","
		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 &amp;amp; vbLf &amp;amp; Matl &amp;amp; vbLf &amp;amp; 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 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cfcf.jpg" style="width: 441px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/934017iDD0A7AD4A3FA3472/image-size/large?v=v2&amp;amp;px=999" role="button" title="cfcf.jpg" alt="cfcf.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 10:39:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-write-custom-iprop-t-assembly-level/m-p/10417149#M125759</guid>
      <dc:creator>bespel</dc:creator>
      <dc:date>2021-06-24T10:39:55Z</dc:date>
    </item>
  </channel>
</rss>

