By Wayne Brill
You can use the HasSaveCopyAsOptions method and the NameValueMap input argument to find the options for the translator. These VBA and VB.NET examples print a list of the save options and values for the DWF Translator AddIn. The AddIn is identified by its description string, so this code can be easily modified to be applied for a different translator AddIns.
VBA
Public Sub GetDWFOptions()
Dim AddInIterator As ApplicationAddIn
‘Find the DWFAddIn based on description string
For Each AddInIterator In ThisApplication. _
ApplicationAddIns
If AddInIterator.AddInType = _
kTranslationApplicationAddIn Then
If AddInIterator.Description = _
"Autodesk Internal DWF Translator" Then
Exit For
End If
End If
Next
‘Activates AddIn
AddInIterator.Activate
‘Gets application translation
‘context and set type to UnspecifiedIOMechanism
Dim Context As TranslationContext
Set Context = ThisApplication.TransientObjects _
.CreateTranslationContext
Context.Type = kUnspecifiedIOMechanism
Dim Options As NameValueMap
Set Options = ThisApplication.TransientObjects _
.CreateNameValueMap
Dim SourceObject As Object
Set SourceObject = ThisApplication.ActiveDocument
‘Checks whether the translator has ‘SaveCopyAs’
‘options. If so, prints all the save options
Dim index As Integer
If AddInIterator.HasSaveCopyAsOptions _
(SourceObject, Context, Options) Then
For index = 1 To Options.count
Debug.Print "[Option Name] " & Options.Name(index) _
& " = " & Options.Value(Options.Name(index))
Next
End If
End Sub
VB.NET
Public Class Form1 Dim m_inventorApp As Inventor.Application _ = Nothing Private Sub Button1_Click(ByVal sender As _ System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click ' Get an active instance of Inventor Try m_inventorApp = System.Runtime. _ InteropServices.Marshal. _ GetActiveObject("Inventor.Application") Catch 'Inventor not started System.Windows.Forms.MessageBox. _ Show("Start an Inventor session") Exit Sub End Try 'Call the Sub GetDWFOptions() End Sub Public Sub GetDWFOptions() Dim AddInIterator As ApplicationAddIn = _ Nothing 'Find the DWFAddIn based on ' description string For Each AddInIterator In m_inventorApp. _ ApplicationAddIns If AddInIterator.AddInType = _ ApplicationAddInTypeEnum. _ kTranslationApplicationAddIn Then If AddInIterator.Description = _ "Autodesk Internal DWF Translator" Then Exit For End If End If Next 'Activates AddIn AddInIterator.Activate() 'Gets application translation context ' and set type to UnspecifiedIOMechanism Dim Context As TranslationContext Context = m_inventorApp.TransientObjects _ .CreateTranslationContext Context.Type = _ IOMechanismEnum.kUnspecifiedIOMechanism Dim Options As NameValueMap Options = m_inventorApp.TransientObjects _ .CreateNameValueMap Dim SourceObject As Object SourceObject = m_inventorApp.ActiveDocument 'Checks whether the translator has ' 'SaveCopyAs() options. 'If so, print all the save options Dim index As Integer If AddInIterator.HasSaveCopyAsOptions _ (SourceObject, Context, Options) Then For index = 1 To Options.Count Debug.Print("[Option Name] " _ & Options.Name(index) _ & " = " _ & Options.Value(Options.Name(index))) Next End If End Sub End Class

Leave a Reply