<?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: Mass Changing Default BOM Structure for multiple parts using VBA Code in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/mass-changing-default-bom-structure-for-multiple-parts-using-vba/m-p/7126358#M72642</link>
    <description>&lt;P&gt;What you had was an ugly mish-mash of excel and inventor coding. Leads me to thing you have 0 understand of how Object-Oriented Programming works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just because a method/property works on one object in one application, that does not mean it's how another application utilizes it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Workbooks is really only an excel thing. You cannot open an ipt file or an iam file in excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this is more along the lines of what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how you have it coded, it only goes 1 level of sub-folders deep. You need to either create a folder list to work through, or write a recursive function to handle such a feat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub ChangeBOMStructToPurchased()
    Dim invApp As Inventor.Application
    invApp = ThisApplication

    Dim FSO As Object
    Dim folder As Object, subfolder As Object
    Dim wb As Object&lt;BR /&gt;    Dim oDoc As Document
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    folderPath = "INSERT FILE PATH HERE"
    Set folder = FSO.GetFolder(folderPath)
        
    For Each wb In folder.Files
        If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then
                Set oDoc = invApp.Documents.Open(wb)
                oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure
                oDoc.Close(False)
        End If
    Next

    For Each subfolder In folder.SubFolders
        For Each wb In subfolder.Files
            If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then
                Set oDoc = invApp.Documents.Open(wb)
                oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure
                oDoc.Close(False)
            End If
        Next
    Next
End Sub&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Jun 2017 20:29:04 GMT</pubDate>
    <dc:creator>MechMachineMan</dc:creator>
    <dc:date>2017-06-02T20:29:04Z</dc:date>
    <item>
      <title>Mass Changing Default BOM Structure for multiple parts using VBA Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/mass-changing-default-bom-structure-for-multiple-parts-using-vba/m-p/7125724#M72641</link>
      <description>&lt;P&gt;I am trying to change the default BOM Structure from Normal to Purchased for over 19,000 parts and assemblies using a string of VBA code to avoiding manually changing the setting for each individual part. I tested my code out in Excel and it worked perfectly, however it does not work in Inventor and I've hit a roadblock trying to troubleshoot it. When ran in Excel, it takes your designated file path and changes values in the specified cell in all excel values inside that folder and subsequent subfolders, just like I would like it to run in Inventor. I'm not sure why it does not work, I assume it has something to do with changing from the Excel program and going to a non-Microsoft program in Inventor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have very little experience in programming and even less in VBA, so any help is appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my Excel code that runs just fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub openWB()&lt;BR /&gt; Dim FSO As Object&lt;BR /&gt; Dim folder As Object, subfolder As Object&lt;BR /&gt; Dim wb As Object&lt;BR /&gt; &lt;BR /&gt; Set FSO = CreateObject("Scripting.FileSystemObject")&lt;BR /&gt; folderPath = "INSERT FILE PATH HERE"&lt;BR /&gt; Set folder = FSO.GetFolder(folderPath)&lt;BR /&gt; &lt;BR /&gt; With Application&lt;BR /&gt; .DisplayAlerts = False&lt;BR /&gt; .ScreenUpdating = False&lt;BR /&gt; .EnableEvents = False&lt;BR /&gt; .AskToUpdateLinks = False&lt;BR /&gt; End With&lt;BR /&gt; &lt;BR /&gt; For Each wb In folder.Files&lt;BR /&gt; If Right(wb.Name, 3) = "xls" Or Right(wb.Name, 4) = "xlsx" Or Right(wb.Name, 4) = "xlsm" Then&lt;BR /&gt; Set masterWB = Workbooks.Open(wb)&lt;BR /&gt; Cells(1, 1).Value = 4000&lt;BR /&gt; ActiveWorkbook.Close True&lt;BR /&gt; End If&lt;BR /&gt; Next&lt;BR /&gt; For Each subfolder In folder.SubFolders&lt;BR /&gt; For Each wb In subfolder.Files&lt;BR /&gt; If Right(wb.Name, 3) = "xls" Or Right(wb.Name, 4) = "xlsx" Or Right(wb.Name, 4) = "xlsm" Then&lt;BR /&gt; Set masterWB = Workbooks.Open(wb)&lt;BR /&gt; Cells(1, 1).Value = 4000&lt;BR /&gt; ActiveWorkbook.Close True&lt;BR /&gt; End If&lt;BR /&gt; Next&lt;BR /&gt; Next&lt;BR /&gt; With Application&lt;BR /&gt; .DisplayAlerts = True&lt;BR /&gt; .ScreenUpdating = True&lt;BR /&gt; .EnableEvents = True&lt;BR /&gt; .AskToUpdateLinks = True&lt;BR /&gt; End With&lt;BR /&gt;End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my Inventor code that either gives a run-time error or runs but does not actually change the default BOM structure (bolded are the main changes from the Excel code):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub openWB()
    Dim FSO As Object
    Dim folder As Object, subfolder As Object
    Dim wb As Object
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    folderPath = "INSERT FILE PATH HERE"
    Set folder = FSO.GetFolder(folderPath)
    
    'With Application
        '.DisplayAlerts = False
        '.ScreenUpdating = False
        '.EnableEvents = False
        '.AskToUpdateLinks = False
    'End With
        
    For Each wb In folder.Files
        &lt;STRONG&gt;If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then&lt;/STRONG&gt;
            Set masterWB = Workbooks.Open(wb)
                &lt;STRONG&gt;Dim oDoc As PartDocument&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;                Set oDoc = ThisApplication.ActiveDocument&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;                oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure&lt;/STRONG&gt;
            ActiveWorkbook.Close True
        End If
    Next
    For Each subfolder In folder.SubFolders
        For Each wb In subfolder.Files
            &lt;STRONG&gt;If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then&lt;/STRONG&gt;
                Set masterWB = Workbooks.Open(wb)
                    &lt;STRONG&gt;Dim oDoc As PartDocument&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;                    Set oDoc = ThisApplication.ActiveDocument&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;                    oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure&lt;/STRONG&gt;
                ActiveWorkbook.Close True
            End If
        Next
    Next
    'With Application
        '.DisplayAlerts = True
        '.ScreenUpdating = True
        '.EnableEvents = True
        '.AskToUpdateLinks = True
    'End With
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 16:11:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/mass-changing-default-bom-structure-for-multiple-parts-using-vba/m-p/7125724#M72641</guid>
      <dc:creator>rhjones74</dc:creator>
      <dc:date>2017-06-02T16:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Mass Changing Default BOM Structure for multiple parts using VBA Code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/mass-changing-default-bom-structure-for-multiple-parts-using-vba/m-p/7126358#M72642</link>
      <description>&lt;P&gt;What you had was an ugly mish-mash of excel and inventor coding. Leads me to thing you have 0 understand of how Object-Oriented Programming works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just because a method/property works on one object in one application, that does not mean it's how another application utilizes it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Workbooks is really only an excel thing. You cannot open an ipt file or an iam file in excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this is more along the lines of what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how you have it coded, it only goes 1 level of sub-folders deep. You need to either create a folder list to work through, or write a recursive function to handle such a feat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub ChangeBOMStructToPurchased()
    Dim invApp As Inventor.Application
    invApp = ThisApplication

    Dim FSO As Object
    Dim folder As Object, subfolder As Object
    Dim wb As Object&lt;BR /&gt;    Dim oDoc As Document
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    folderPath = "INSERT FILE PATH HERE"
    Set folder = FSO.GetFolder(folderPath)
        
    For Each wb In folder.Files
        If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then
                Set oDoc = invApp.Documents.Open(wb)
                oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure
                oDoc.Close(False)
        End If
    Next

    For Each subfolder In folder.SubFolders
        For Each wb In subfolder.Files
            If Right(wb.Name, 3) = "ipt" Or Right(wb.Name, 3) = "iam" Then
                Set oDoc = invApp.Documents.Open(wb)
                oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure
                oDoc.Close(False)
            End If
        Next
    Next
End Sub&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Jun 2017 20:29:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/mass-changing-default-bom-structure-for-multiple-parts-using-vba/m-p/7126358#M72642</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-06-02T20:29:04Z</dc:date>
    </item>
  </channel>
</rss>

