Share

API - Export Factory and Inventor Instance Data

This API sample demonstrates how you can extract asset instance properties together with Inventor iProperties to create a custom BOM by exporting the data to an Excel spreadsheet.

The following script shows you how to access your Factory data and Inventor data for the same object.

Note: To use this script, you need to be familiar with iLogic. To learn more about iLogic, see Inventor iLogic in the Inventor online Help system.
AddReference "Autodesk.Factory.PublicAPI.dll"
Imports Autodesk.Factory.PublicAPI.Currency.v2

Sub Main()
    Dim occ As ComponentOccurrence , factoryInstance As IAssetInstance
    occ = GetOccurenceToWorkWith()

    If occ Is Nothing
        Exit Sub
    End If

    If (Not IsFactoryInstance(ThisApplication.ActiveDocument, occ, factoryInstance)) Then
        MessageBox.Show("The object you selected is not a Factory Design asset instance", "iLogic sample rule")
        Exit Sub
    End If

    Dim instanceID = factoryInstance.InstanceID
    Dim partNumber = iProperties.Value(occ.Name, "Project", "Part Number")
    MessageBox.Show (instanceID, "Factory Instance ID")
    MessageBox.Show (partNumber, "Inventor Part Number")
End Sub

Function GetOccurenceToWorkWith() As ComponentOccurrence
    Dim comp As Object

    comp = ThisApplication.CommandManager.Pick( 
                                            SelectionFilterEnum.kAssemblyOccurrenceFilter, 
                                            "Select a Factory Asset instance in the layout")
    If IsNothing(comp) Then 
        Return Nothing
    Else
        Return comp 
    End If
End Function

Function IsFactoryInstance(layoutDoc As Document, occ As ComponentOccurrence, ByRef factoryInstance As IAssetInstance)
    Dim instances = Autodesk.Factory.PublicAPI.API.Instance.GetAssetInstances(layoutDoc)
    found = False
    For Each instance In instances
        If instance.NativeObject.Equals(occ) Then
            factoryInstance = instance
            found = True
            Exit For
        End If
    Next
    Return found
End Function

Was this information helpful?