It has been some time since I was regularly programming. My background was C++ and I was moving to C# when, well, I started writing; it appears as though there is only enough time to either research engineering software, or research software API.

Recently I decided I wanted some drawing automation; something to take care of the repetitive tasks beyond a good template. Being quite detail oriented, I like a complete drawing. This requires a lot of copying parent exploded views, parts lists, and so forth. While creating an iLogic drawing iProperties checker, I thought iLogic could help me with the drawing creation as well.

What follows is a collection of key notes that I made during my iLogic Assembly document function research; these are the same functions we used to develop the automated drawing creation tool.

Autodesk Inventor API Chart

We will look briefly at the general Document class in this article, and then take a bit of time stepping into the Assembly Document container hierarchy in a follow up.

Introduction

It is very important to understand the Inventor assembly document structure and hierarchy. Each component in an assembly is a Document. Each Document is simply a reference to a file that is, or will be upon saving, stored on a file server or local drive.

Documents however can be interpreted in numerous ways. In our case, Documents represent Parts, Assemblies, Spreadsheets, Drawings, etc. Inventor has Class Objects that have intelligence built in to deal with how an Assembly Document, for example, will behave.

Just Give Me Everything

First, we can get all file references by calling for ‘AllReferencedDocuments’. This function is basically a document dump.

Base Object Class: Document

Type: Function Call

Object Function:  AllReferencedDocuments

Returns: Document object

This function does a jam-up job of returning all FILE instances within any Document object. Only one instance per file is returned, regardless of how many times a part is used in an assembly.

This function is not reserved to Assembly files and will work on any Document class based object. This makes it a great, universal front end build for code that needs to work in a broad range of Inventor documents.

Caution should be used to provide significant bounds checking as to what type of Document is being returned, as AllReferencedDocuments will return anything at all; Spreadsheets, Part files, you name it.

Example: (working with only the part files in a document)

‘ Get the active assembly document.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
‘ Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments

‘ Verify that the document is a part.
If oDoc.DocumentType = kPartDocumentObject Then
Dim oPartDoc As PartDocument
oPartDoc = oDoc

‘——————
‘Do something with the part document here
‘——————-

End If
Next

This is great when you want everything, but I need to see some structure, and having some refinement would be nice. We’ll return with those details and the Assembly Document container hierarchy in the follow-up article.

REFERENCES:

Mod The Machine article “Accessing Assembly Components” from 2009

The Autodesk Inventor 2014 API chart

Mod the Machine Article “Understanding File References” from 2008