<?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: Loop through BOM in assembly and get iProperties using Apprentice in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8960309#M72709</link>
    <description>&lt;P&gt;Thank you very much for your help. I have already used a different solution, i.e. to export BOM to Excel with full file path and then load it into my program, where I reference each file path in the assembly and I use InventorView activeX component to display parts and subassemblies within my program. As I need to do it only once, it is no big deal. But when I have time, I will try your solution too.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Aug 2019 05:20:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-12T05:20:45Z</dc:date>
    <item>
      <title>Loop through BOM in assembly and get iProperties using Apprentice</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8949916#M72707</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to ask if it is possible to loop through the assembly file using Apprentice Server and export information from BOM (part number, description, . I read everywhere that people can access BOM through Apprentice Server but I never found a working solution how to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would need Part number, Description, Category, item QTY, Mass, G_L (custom parameter for unit length), Full file Path.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I reference :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;oApprentice&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;As&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ApprenticeServerComponent&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; oApprentice =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;New&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ApprenticeServerComponent&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;' Open a document.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;oDoc&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;As&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ApprenticeServerDocument&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; Dim oBom as inventor.bom&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; oDoc = oApprentice.Open(&lt;SPAN&gt;"filename.iam"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; oBom&amp;nbsp; = &lt;STRONG&gt;oDoc.componentdefinition.bom&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;lt;- This property/method is not available in Apprentice&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Can you please help me how to do it correctly.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thank you.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 04:29:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8949916#M72707</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-06T04:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through BOM in assembly and get iProperties using Apprentice</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8958981#M72708</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;in the &lt;A href="http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-F2A12822-98DE-4638-B1C7-6BEEF821D50A" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; i could only find: "&lt;EM&gt;Apprentice provides access to file references, assembly structure, B-Rep, geometry, attributes, render styles, and document properties.&lt;/EM&gt;" In the ApprenticeServerDocument object i could also not find any reference to a BOM object (like in the full Inventor api).&lt;/P&gt;&lt;P&gt;But it is possible to acces the assembly structure. therefor you could write your own BOM/List object. something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;c# (console application)&lt;/P&gt;&lt;PRE&gt;class Program
    {
        private static Dictionary&amp;lt;string,BomItem&amp;gt; BOM = new Dictionary&amp;lt;string,BomItem&amp;gt;();

        static void Main(string[] args)
        {
            string fileName = @"C:\temp\Assembly2.iam";
            ApprenticeServerComponent apprentice = new ApprenticeServerComponent();
            ApprenticeServerDocument apprenticeDoc = apprentice.Open(fileName);

            createPartsOnlyBom(apprenticeDoc);

            foreach (KeyValuePair&amp;lt;string, BomItem&amp;gt; item in BOM)
            {
                BomItem b = item.Value;
                Console.WriteLine("{0}|{1}|{2}",b.qty, b.fullFileName,b.partNumber);
            }
            Console.ReadKey();
        }

        public static void createPartsOnlyBom(ApprenticeServerDocument doc)
        {
            foreach (ComponentOccurrence occ in doc.ComponentDefinition.Occurrences)
            {
                if (occ.ReferencedDocumentDescriptor.ReferencedDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    createPartsOnlyBom(occ.ReferencedDocumentDescriptor.ReferencedDocument);
                }
                else
                {
                    if (occ.BOMStructure == BOMStructureEnum.kNormalBOMStructure ||
                    occ.BOMStructure == BOMStructureEnum.kPhantomBOMStructure)
                    {
                        string fulldocName = occ.ReferencedDocumentDescriptor.FullDocumentName;
                        if (BOM.ContainsKey(fulldocName) == false)
                        {
                            ApprenticeServerDocument docOcc = occ.ReferencedDocumentDescriptor.ReferencedDocument;
                            
                            BomItem newItem = new BomItem();
                            newItem.fullFileName = fulldocName;
                            newItem.qty = 1;
                            newItem.partNumber = docOcc.PropertySets["Design Tracking Properties"]["Part number"].Value;
                            BOM.Add(fulldocName, newItem);
                        }
                        else
                        {
                            BOM[fulldocName].qty += 1;
                        }
                    }
                }
            }
        }
    }

    public class BomItem
    {
        public string fullFileName;
        public int qty;
        public string partNumber;
    }&lt;/PRE&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>Sat, 10 Aug 2019 11:10:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8958981#M72708</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2019-08-10T11:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through BOM in assembly and get iProperties using Apprentice</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8960309#M72709</link>
      <description>&lt;P&gt;Thank you very much for your help. I have already used a different solution, i.e. to export BOM to Excel with full file path and then load it into my program, where I reference each file path in the assembly and I use InventorView activeX component to display parts and subassemblies within my program. As I need to do it only once, it is no big deal. But when I have time, I will try your solution too.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 05:20:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/loop-through-bom-in-assembly-and-get-iproperties-using/m-p/8960309#M72709</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-12T05:20:45Z</dc:date>
    </item>
  </channel>
</rss>

