- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorry if this is the wrong section.
I'm currently working on a VBA script in Excel that interfaces with Inventor Professional 2023. The code i've got right now grabs the BOM from an assembly and compares it with data from our ERP system. This is to ensure part numbers and naming conventions are correctly typed in both systems. This comparison functionality is split into different modules to handle both legacy data and this inventor generated data.
My problem arises when i try to handle the case where the user has the assembly drawing open rather than the 3d model of the assembly. I'd like to somehow access/open the assembly, and get its document, namely in the form of a "kAssemblyDocumentObject", using the "kDrawingDocumentObject" that I currently have. If i can find a way to do that then the rest of my code will work perfectly.
I'm fairly new to coding in general, and this is my first project with inventor so if you guys have any suggestions, it would be greatly appreciated 🙂
Below is a snippit of my code:
Public Sub GenerateRecursiveBOMFromActiveInventorAssemblyV2()
Dim invApp As Inventor.Application
' Attempt to connect to a running Inventor instance
On Error Resume Next
Set invApp = GetObject(, "Inventor.Application")
On Error GoTo 0
If invApp Is Nothing Then
MsgBox "Inventor was not running."
Exit Sub
End If
Dim oDoc As Inventor.Document
Set oDoc = invApp.ActiveDocument
If oDoc Is Nothing Then
MsgBox "No active document in Inventor.", vbExclamation
Exit Sub
End If
' Handle edge cases where the current document isnt an assembly
If oDoc.DocumentType <> kAssemblyDocumentObject Then
' Is it a drawing? Then try to access linked assembly
If oDoc.DocumentType = kDrawingDocumentObject Then
MsgBox "This is a drawing, here it should change the focused document to the attached assembly"
End If
Exit Sub
End If
Dim oAsmDoc As Inventor.AssemblyDocument
Set oAsmDoc = oDoc
'... Rest of the script that handles comparison of BOM with ERP system below here
End Sub
The full code can be seen in the attached file. The forum doesnt accept .bas files, so its stored as a .txt 🙂
Solved! Go to Solution.