<?xml encoding=”UTF-8″>By Adam Nagy
The 2014 version of the Inventor API Help file provides better description of the available options of OpenWithOptions:
Documents.OpenWithOptions Method
Parent Object: Documents
Description
Method that opens the specified Inventor document.
Syntax
Documents.OpenWithOptions( FullDocumentName As String, Options As NameValueMap, [OpenVisible] As Boolean ) As Document
Parameters
| Name | Description |
| FullDocumentName | Input String that specifies the full document name of the document to open. If only the FullFileName is specified for an assembly, the master document within the file is opened. |
| Options | Input NameValueMap object that specifies additional options for open. (An empty NameValueMap object can be provided). See Remarks section for the valid options. |
| OpenVisible | Optional input Boolean that specifies whether to open the document as visible. If not specified, the document is opened visible. |
Remarks
Valid values for the NameValueMap in the Options argument:
| Name | Type | Valid Document Type | Notes |
| DesignViewRepresentation | String | Part, Assembly | The name of the design view representation. |
| PositionalRepresentation | String | Assembly | The name of the positional representation. |
| LevelOfDetailRepresentation | String | Assembly | Typically, the LevelOfDetailRepresentation to use should be provided in the form of a FulDocumentName (first argument). But if this is provided separately, you should make sure that it does not conflict with the FullDocumentName argument by providing FullFileName as the first argument rather than a FullDocumentName. |
| DeferUpdates | Boolean | Drawing | Indicates if any pending updates for the drawing will be deferred when the drawing is opened. |
| FileVersionOption | Value from FileVersionEnum | All | Valid values for FileVersionEnum are kOpenOldVersion, kOpenCurrentVersion and kRestoreOldVersionToCurrent. If set to kOpenOldVersion, save will not be allowed on the opened document. kRestoreOldVersionToCurrent is valid only if no other versions are open and the current version is not checked out. |
| ImportNonInventorDWG | Boolean | Imports the DWG file to an IDW if True, Opens it into Inventor DWG if False | When opening non-Inventor DWG files, this method honors the application option to decide between open and import, unless an override is specified in the Options argument. |
| Password | String | All | |
| SkipAllUnresolvedFiles | Boolean | All | Indicates to skip all unresolved files and continue to open the document. |
| ExpressModeBehavior | String | Assembly |
The following values are valid for this setting:
OpenExpress – Open the assembly in express mode. OpenFull – Open the assembly in full mode. OpenDefault – Open the assembly in the mode it was saved in. |
As you can see it does not seem to have the option for Import Unit. However the SAT Translator Addin has that. So we can use that instead. The API Help File’s Translator Options topic contains all the available options, including ImportUnit: SOURCE_UNITS = 0,
TEMPLATE_UNITS = 1, INCH = 2, FOOT = 3, CENTIMETER = 4, MILLIMETER = 5, METER = 6, MICRON = 7.
You can start with e.g. the API Help File’s Open an STL file using the STL Translator Sample API Sample and modify it to use the SAT Translator instead along with the ImportUnit setting:
Sub ImportFunc()
' Set SAT translator's CLSID and SAT file name.
Dim strCLSID As String
Dim strFileName As String
strCLSID = "{89162634-02B6-11D5-8E80-0010B541CD80}"
strFileName = "C:Sample.sat"
Dim oAddIns As ApplicationAddIns
Set oAddIns = ThisApplication.ApplicationAddIns
' Find the SAT translator, get the CLSID and activate it.
Dim oTransAddIn As TranslatorAddIn
Set oTransAddIn = oAddIns.ItemById(strCLSID)
oTransAddIn.Activate
' Get the transient object and take it as a factory
' to produce other objects
Dim transientObj As TransientObjects
Set transientObj = ThisApplication.TransientObjects
' Prepare the first parameter for Open(), the file name
Dim file As DataMedium
Set file = transientObj.CreateDataMedium
file.FileName = strFileName
' Prepare the second parameter for Open(), the open type.
Dim context As TranslationContext
Set context = transientObj.CreateTranslationContext
context.Type = kDataDropIOMechanism
' Prepare the 3rd parameter for Open(), the options.
Dim options As NameValueMap
Set options = transientObj.CreateNameValueMap
' Have a look at the API Help File's 'Translator Options'
options.Value("ImportUnit") = 4 'CENTIMETER
' Prepare the fourth parameter for Open(), the final document.
Dim sourceObj As Object
' Open the SAT file.
oTransAddIn.Open file, context, options, sourceObj
End Sub

Leave a Reply