Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
MechMachineMan
in reply to: rhjones74

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.

 

Just because a method/property works on one object in one application, that does not mean it's how another application utilizes it.

 

Workbooks is really only an excel thing. You cannot open an ipt file or an iam file in excel.

 

Something like this is more along the lines of what you are looking for.

 

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.

 

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
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

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
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