Open-Document
Opens the specified document in one of the registered application.
Syntax
1 | Open-Document -LocalFile <string> [-Application <string>] [-Options <HashTable/string>] [<CommonParameters>] |
Parameters
Type |
Name |
Description |
Optional |
---|---|---|---|
String |
LocalFile |
The path to the document that should be opened |
no |
String |
Application |
Can be used to force opening the document with a specific application by specifying its Name. |
yes |
HashTable / String |
Options |
The application will open the document with the passed options |
yes |
Return type
Bool: on success the cmdlet returns $true otherwise $false.
The result has additional properties:
$result.Error ← Error contains the Exception object
$result.Application ← Application is an implementation of the IApplication Interface
$result.Document ← Document is an implementation of the IDocument Interface
Remarks
When no -Application parameter is specified, the best matching application for the document is determinded automatically:
Only registered applications that are installed and support the -LocalFile are taken into account.
AutoCAD documents are preferably always opened in DWG TrueView, and for Inventor documents Inventor is used by default (if installed).
Many documents can be opened by multiple applications, so it ultimately depends on the registration order which application is used to open the specified file.
For example, Inventor documents can be opened from Inventor and InventorServer. In this case the first-registered application in the coolOrange.Applications.psm1 module is used for opening by default
(see example: Prefer opening documents with InventorServer by default instead of Inventor).
Document type: AutoCAD DWG
When the cmdlet is used to open AutoCAD DWG files without specifying the -Application parameter, the DWG TrueView application is used, without considering the order of registrations.
If the DWG TrueView application is not registered or not installed, the best matching application is chosen using the algorithm described above.
Depending on the application that opens the document, application specific default -Options are be used.
To check which options were used to open the document, $result.Document.OpenSettings
can be used: it contains all the properties used to open the document.
The following section lists all possible options for the default applications:
Inventor and InventorServer
For Inventor and InventorServer the project file can be specified via @{'Project'='C:\temp\test.ipj'}
.
Additionally all the options of the API method OpenWithOptions can be used, eg @{'Fast Open'=$true; 'LevelOfDetailRepresentation'='Master'}
:
Type |
Name |
Description |
Default |
---|---|---|---|
string / System.IO.FileInfo |
Project |
The ProjectFile that Inventor uses to open the document. Possible: |
Current Inventor Project |
bool / string |
Visible |
Specifies whether the document should be opened visible or invisible. Possible: |
True |
string |
DesignViewRepresentation |
Only for assemblies and parts |
For assemblies the first DesignViewRepresentations of the document |
string |
PositionalRepresentation |
Only for assemblies |
|
string |
LevelOfDetailRepresentation |
Only for assemblies. Supported in Inventor versions 2021 and earlier |
Last saved LevelOfDetailRepresentation of the document, e.g. ‘Master’ |
string |
ModelState |
Only for assemblies and parts. Supported in Inventor from version 2022 |
The ‘Master’ model state |
bool |
DeferUpdates |
Only for drawings |
|
FileVersionEnum |
FileVersionOption |
||
bool |
ImportNonInventorDwg |
False |
|
string |
Password |
||
ExpressModeBehavior |
ExpressModeBehavior |
Only for assemblies |
|
bool |
SkipAllUnresolvedFiles |
False |
|
bool |
DeferFlatPatternUpdate |
Only for sheet metal parts |
False |
bool |
FastOpen |
Only for drawings |
False |
DWG TrueView
DWG TrueView has only the following options:
Type |
Name |
Description |
Default |
---|---|---|---|
bool / string |
Readonly |
Specifies wether the document should be opened in readonly mode or not. Possible: |
False |
Examples
Opening an AutoCAD DWG file
1 | Open-Document -LocalFile 'C:\Vault\AutoCad\Drawings\Tablet.dwg' |
Prefer opening documents with InventorServer by default instead of Inventor
Because Inventor and InventorServer can both open the same document formats, the Open-Document cmdlet will consider the order of the application registrations by default (see Remarks).
Therefore, if you prefer to use InventorServer as default over Inventor, then just switch the registration lines in the coolOrange.Applications.psm1 module, so that InventorServer is registered first:
18 19 | Register-Application ([powerJobs.Application.Inventor.Server.Application]) Register-Application ([powerJobs.Application.Inventor.Application]) |
1 2 3 | $result = Open-Document -LocalFile 'C:\Vault\Inventor\Drawings\Pad Lock.idw' $result.Application.Name #Returns: InventorServer |
Opening an AutoCAD DWG file with InventorServer by forcing it
1 | $result = Open-Document -LocalFile 'C:\Vault\AutoCad\Drawings\Tablet.dwg' |
Opening an Inventor drawing with specified project file and FastOpen
1 2 3 4 | Open-Document -LocalFile 'C:\Vault\Inventor\Drawings\Pad Lock.idw' -Options @{ 'Project'='C:\Vault\Default.ipj'; 'FastOpen'=$true } |
Using the result to validate if document was opened successfully
1 2 3 4 | $result = Open-Document C:\Temp\Test.ipt if(-not $result) { throw "Failed with error: $($result.Error.Message)" } |
Using the Application- and Document properties of the result
1 2 3 4 5 6 7 8 9 | $result = Open-Document C:\Vault\Inventor\SheetMetal.ipt if($result.Application.Name -eq 'Inventor') { $result.Application.Instance.Visible = $true if ($result.Document.Instance.ComponentDefinition.Type -ne [Inventor.ObjectTypeEnum]::kSheetMetalComponentDefinitionObject) { throw "The file 'SheetMetal.ipt' is not a sheet metal part!" } #... } |