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.
Otherwise a valid application will be detected automatically.

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 the -Application parameter is not specified, the best matching application for the document is determined automatically:

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; 'ModelState'='Master'}:

Type

Name

Description

Default

string / System.IO.FileInfo

Project

The ProjectFile that Inventor uses to open the document. Possible: 'C:\somefile.ipj', [file]'C:\somefile.Ipj'

Current Inventor Project

bool / string

Visible

Specifies whether the document should be opened visible or invisible. Possible: $true,'False','TRUE'

True

string

DesignViewRepresentation

Only for assemblies and parts

For assemblies the first DesignViewRepresentations of the document

string

PositionalRepresentation

Only for assemblies

string

ModelState

Only for assemblies and parts.

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: $true,'False','TRUE'

False

Examples

Opening an AutoCAD DWG file

1
2
3
4
$result = Open-Document -LocalFile 'C:\Vault\AutoCad\Drawings\Tablet.dwg'

$result.Application.Name
#Returns: DWG TrueView

Opening an AutoCAD DWG file with Inventor by forcing it

1
2
3
4
$result = Open-Document -LocalFile 'C:\Vault\AutoCad\Drawings\Tablet.dwg' -Application 'Inventor'

$result.Application.Name
#Returns: Inventor

Prefer opening Inventor 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
4
$result = Open-Document -LocalFile 'C:\Vault\Inventor\Drawings\Pad Lock.idw'

$result.Application.Name
#Returns: InventorServer

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 result to access the Inventor API (application made visible for Debugging)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$result = Open-Document 'C:\Vault\Inventor\SheetMetal.ipt'

if($result.Application.Name -eq 'Inventor') {
	$result.Application.Instance.Visible = $true # makes the instrumented Inventor window visible
	$result.Application.Instance.UserInterfaceManager.UserInteractionDisabled = $false # allows to click around in the window for testing purposes
}

# the following API accesses work for Inventor and InventorServer:
if ($result.Document.Instance.ComponentDefinition.Type -ne [Inventor.ObjectTypeEnum]::kSheetMetalComponentDefinitionObject) {
	throw "The file 'SheetMetal.ipt' is not a sheet metal part!"
}