Close-Document

Closes an open document.

Syntax

1
Close-Document [-Save] [-Document <IDocument>] [<CommonParameters>]

Parameters

Type

Name

Description

Optional

IDocument

Document

The cmdlet will close this document. Otherwise, the last opened document will be closed

yes

Boolean

Save

The application will save the document on close

yes

Return type

Bool: on success the cmdlet returns $true otherwise $false.
$result.Error <- The result has additionally an Error property which contains the Exception object
$result.Application <- Application is an implementation of IApplication
$result.Document <- Document is an implementation of IDocument

Remarks

After all documents got closed in Inventor or InventorServer, the active project file will be resetet to the original project file.

Examples

Closing the last opened document

1
2
3
Open-Document -localFile 'C:\Vault\Test.ipt'

Close-Document

Closing a specific document

1
2
3
4
$open1 = Open-Document -localFile 'C:\Vault\Test.ipt'
$open2 = Open-Document -localFile 'C:\Vault\Test.ipt'

Close-Document -Document $open1.Document

Checking if document was closed successfully

1
2
3
4
$result = Close-Document
if(-not $result) {
	throw "Failed to save and close document with error: ". $result.Error.Message
}

Close and Save document

1
2
3
$openResult = Open-Document -localFile 'C:\Vault\Test.ipt'
...
Close-Document -Document $openResult.Document -Save $true

Using the close result

1
2
3
$result = Close-Document if($result.Application.Name -eq 'Inventor') {
	$result.Application.Instance.Visible = $true
}