Get Option Names and Values Supported by Inventor Translator Addins via API

Issue
How can I get the options when Save Copy As an Inventor file to DWF/DWG/DXF/IGES/STEP/SAT format via API?

Solution
Inventor provides various translator addins for exporting file in other format, like as DWF, DWG, DXF, IGES, STEP, SAT, etc. Viewing Inventor API help document is a way to get those names and values of options supported by numbers of translator addins, but sometimes the document doesn’t tell complete data, or you have to get those options through code. The following VBA sample code prints all options for DWF translator:

Sub GetDwfOptions()
  Dim app As Application
  Set app = ThisApplication
  Dim addins As ApplicationAddIns
  Set addins = app.ApplicationAddIns
  ' Get the DWF AddIn using its ID
  Dim DWFAddIn As TranslatorAddIn
  Set DWFAddIn = _
    addins.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
  ' Activate AddIn
  DWFAddIn.Activate
  Dim SourceObject As Object
  Dim Context As TranslationContext
  Dim Options As NameValueMap
  Dim transientObj As TransientObjects
  Set transientObj = app.TransientObjects
  Set Context = transientObj.CreateTranslationContext
  Context.Type = kUnspecifiedIOMechanism
  Set Options = transientObj.CreateNameValueMap
  Set SourceObject = ThisApplication.ActiveDocument
  ' Check if the translator has 'SaveCopyAs' options
  If DWFAddIn.HasSaveCopyAsOptions( _
    SourceObject, Context, Options) Then
    ' You can also show the Options dialog
    ' and then set whatever you need, then
    ' check here how those settings are stored
    Call DWFAddIn.ShowSaveCopyAsOptions( _
      SourceObject, Context, Options)
    ' Now print out the values
    Call PrintInfo(Options, 1)
  End If
End Sub

Sub PrintInfo(v As Variant, indent As Integer)
  If TypeOf v Is NameValueMap Then
    Dim nvm As NameValueMap
    Set nvm = v
    Dim i As Integer
    For i = 1 To nvm.count
      Debug.Print Tab(indent); nvm.name(i)
      Call PrintInfo(nvm.value(nvm.name(i)), indent + 1)
    Next
  Else
    Debug.Print Tab(indent); v
  End If
End Sub

You may get different options depending on the type of document you are in. Using ShowSaveCopyAsOptions seems to also make sure that all available options are listed: e.g. without calling it the “Sheets” option does not get listed in case of a drawing document.

You can do the same with other type of translator addins as long as replacing the value of ClassIdString with the specific one. But what is the ClassIdString for a specific translator addin? Don’t worry, the below sample can be used to print the ClassIdString of every translator addin for you:

Public Sub GetInfoForAddins()
  Dim addins As ApplicationAddIns
  Set addins = ThisApplication.ApplicationAddIns
  Dim addin As ApplicationAddIn
  For Each addin In addins
    If TypeOf addin Is TranslatorAddIn Then
      Debug.Print addin.DisplayName & addin.ClassIdString
    End If
  Next
End Sub

In the case of formats that support the usage of ini files, the settings you want might be stored there. So set up everything as you want in the Options dialog, then save the ini file – in the case of the DWG Export it’s here:

Screenshot of the 'Save As' dialog in Autodesk Inventor showing export options for a drawing file, with the 'Save Configuration' button highlighted.

Comments

2 responses to “Get Option Names and Values Supported by Inventor Translator Addins via API”

  1. noontz Avatar
    noontz

    WOW.. Thanks.. Implemented this in C# and works as a charm.
    Babara : You are “most wanted person” over at the folks making the Inventor SDK help files. ( If there is anybody there? )

  2. Hi,
    any Problems with this in Inventor 2014?
    this line brings a error
    Set transientObj = app.TransientObjects
    thx
    Mario
    P.s. i have a ADN Subscription also

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading