Open a iam file with excel VBA

Open a iam file with excel VBA

Fieger
Observer Observer
1,685 Views
1 Reply
Message 1 of 2

Open a iam file with excel VBA

Fieger
Observer
Observer

Hello there

 

is there a way to open a inventor file (.iam) with excel VBA?

 

I use a path!!!

 

Thank you

 

Alex

0 Likes
1,686 Views
1 Reply
Reply (1)
Message 2 of 2

wayne.brill
Collaborator
Collaborator

Hi Alex,

 

In Excel VBA first reference the Inventor Object Library:

VBA_References.jpg

 

 

Then use GetObject or CreateObject to connect to a running session of Inventor or create a new session.  This post has an example:

http://forums.autodesk.com/t5/inventor-customization/getobject-need-help/m-p/759841/highlight/true#M...

 

 

Once you have the Inventor Application object you can use the Open method of the Documents collection. Below is an Inventor VBA example from the help file. It shows how to open an assembly with a level of detail. You could just change it and pass in the path to your assembly.  

 

 

Public Sub OpenDocumentInLastActiveLOD()
    Dim strFullFileName As String
    strFullFileName = "C:\temp\Assembly1.iam"
    
    ' Set a reference to the FileManager object.
    Dim oFileManager As FileManager
    Set oFileManager = ThisApplication.FileManager
    
    ' Get the name of the last active Level of Detail (LOD) Representation.
    Dim strLastActiveLOD As String
    strLastActiveLOD = oFileManager.GetLastActiveLevelOfDetailRepresentation(strFullFileName)
    
    ' Use the full file name and LOD name to get the full document name.
    Dim strFullDocumentName As String
    strFullDocumentName = oFileManager.GetFullDocumentName(strFullFileName, strLastActiveLOD)
    
    ' Open the document in the last active LOD.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.Documents.Open(strFullDocumentName)
End Sub

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes