Export-Document

Exports the document in the specified format.

Syntax

1
Export-Document -To <String> [-Format <String>] [-Options <Hashtable | String>] [-Document <IDocument>] [-OnExport <Scriptblock | String>] [<CommonParameters>]

Parameters

Type

Name

Description

Optional

String

To

Location where the converted file should be saved

no

String

Format

File extensions:PDF, DWF / DWFX , IGES , STEP , DXF , DWG , GIF , BMP , TIFF , PNG , JPEG.
If not specified the export allows to place your custom logic in -OnExport

yes

Hashtable / String

Options

The document will be exported with the passed options, or configuration Files

yes

IDocument

Document

The cmdlet will export this document, otherwise the last opened document will be exported

yes

Scriptblock / String

OnExport

The script block or function that will be executed after collecting the options but before the real export starts

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

When passing invalid -Options the export will not fail, in that case the default settings will be used.

OnExport

For the -OnExport parameter it is either possible to pass a function name or a script block, which will be executed before the actual export starts.
Therefore the export of the document fails when an exception is thrown within this parameter.

Following parameters are available: $export, $document (=IDocument), $application (=IApplication).
Depending on the application and the output format, the export object has different types.
Independent of the type, the $export object has always following base properties:

Type

Name

Description

Access type

string

Name

The name of the export is the fromat that you pass to the cmdlet

read-only

IApplication

Application

The application which is used for the export.

read-only

IDocument

SourceDocument

The document that will be exported

read-only

IFileInfo

DestinationFile

The output location and name that was passed to the cmdlet

read-only

ExportSettings

Settings

The exporting options that are used for the export. ExportSettings.Options real HashTable entiries of -Options

read-only

HashSet

SupportedDocumentTypes

Conatins all the supported input formats of the export

read-only

TranslatorAddin

Exports: PDF, DWF/DWFX, DWG, DXF, IGES, STEP,
Application: Inventor, InventorServer

Exports that are using the TranslatorAddin are working with a rich $export object, that can be manipulated in different ways.
Additional to the base properties, a TranslatorAddinExport has following properties:

Type

Name

Description

Access type

string

TranslatorName

The ID of the translator that is used. Usually this is a GUID

read-write

TranslatorAddIn

TranslatorAddin

Represents the Inventor API TranslatorAddin object. By default it is created by using the TranslatorName

read-write

TranslationContext

Context

Represents the Inventor API TranslationContext. By default a new one is created with Type IOMechanismEnum.kFileBrowseIOMechanism

read-write

Hashtable

Options

Represents the -Options that are passed to the cmldet. When passing INI files, this hash contains already it’s data. Options are only set, when HasSaveCopyAsOptions returns True

read-write

DataMedium

DataMedium

Represents the Inventor API DataMedium. By default FileName is set to the destination file from -To argument

read-write

DataIO

Exports: DWG, DXF
Application: Inventor, InventorServer

Exports that are using the DataIO are the ones for exporting SheetMetal documents.
Additional to the base properties, a SheetMetalExport has following properties:

Type

Name

Description

Access type

string

Format

The first options part for DataIO export, e.g. FLAT PATTERN DWG?…

read

SheetMetalComponentDefinition

SheetMetalComponentDefinition

Represents the Inventor API SheetMetalComponentDefinition

read-write

bool

Unfold

when set to True, the SheetMetal will be unfold. By default it is set to !HasFlatPattern

read-write

DataIO

Data

Represents the Inventor API DataIO object. It is the DataIO value of the SheetMetalComponentDefinition

read

Hashtable

Options

Represents the -Options that are passed to the cmldet. When passing INI files, this hash contains already it’s data.
All the Options are formatted as this when passing to DataIO options: FLAT PATTERN DXF?AcadVersion=2000&BendLayer=IV_BEND

read-write

SaveAs

Exports: BMP, GIF, JPEG, PNG, TIFF
Application: Inventor, InventorServer

The $export object of exports that are working with SaveAs, has only the property SaveAsCopy to configure as an bool. By default this setting is set to True.

TrueView

Exports: PDF, DWF/DWFx
Application: DWG TrueView

Exports that are using DWG TrueView as an application have in addtion to the base properties, a property DSDFile.

Type

Name

Description

Access type

FileInfo

DSDFile

This property exposes multitple properties which allow you to easy manipulate the dsd file

read-write

Examples

Exporting the last opened document to DXF with default options

Open-Document -LocalFile 'C:\Vault\AutoCad\bottom_plate.dwg' -Application 'InventorServer'

Export-Document -Format DWF -To 'C:\Vault\AutoCad\bottom_plate.dxf'

Exporting with Options

1
2
Export-Document -format DXF -To C:\Temp\Test.dxf -Options C:\Temp\test.ini
Export-Document -format PDF -To C:\Temp\Test.dxf -Options @{'Vector_Resolution'='50000'}

Exporting multiple documents

1
2
3
4
5
$partDocument = Open-Document -LocalFile 'C:\Vault\Designs\Padlock\External\Case Back.ipt'
$assemblyDocument = Open-Document -LocalFile 'C:\Vault\Designs\Padlock\Assemblies\Pad Lock.iam'

Export-Document -Document $partDocument.Document -format JPEG -To C:\Temp\Case Back.jpg
Export-Document -Document $assemblyDocument.Document -format BMP -To C:\Temp\Pad Lock.bmp

Validating Export result

1
2
3
4
$result = Export-Document -format PDF -To C:\Temp\Test.pdf
if(-not $result) {
	throw "Failed to export with error: ". $result.Error.Message
}

Using the export result

1
2
3
4
$result = Export-Document -format PDF -To C:\Temp\Test.pdf if($result.Application.Name -eq 'Inventor') {
	$result.Document.Instance
	#...
}

Handling exceptions thrown in OnExport script block

1
2
3
4
5
6
$exportResult = Export-Document -Format DWF -To C:\Temp\Test.dwf -OnExport {
	#Statement throwing exception
}
if(!$exportResult -and $null -ne $exportResult.Error.InnerException) {
	Write-Host ("Exception thrown in OnExport: " + $exportResult.Error.InnerException.ErrorRecord)
}

Exporting with even more possibilities in OnExport script block

1
2
3
4
5
6
7
8
Export-Document -format PDF -To C:\Temp\Test.pdf -Options C:\Temp\PDF.ini -onExport {
	param($export)

	$export.Options['All_Color_AS_Black']='1'
	$export.Options.Remove('Password_protect')
	$export.Options.Remove('Password')
	#...
}

Doing special stuff in the OnExport, by using the Inventor API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Open-Document -LocalFile 'C:\Vault\Designs\Padlock\Assemblies\Pad Lock.iam'
$result = Export-Document -Format DWF -To C:\Temp\Test.dwf -OnExport {
	param($export)

	$document = $export.SourceDocument
	$export.Application.Instance.Visible=$true
	if($document.Instance.DocumentType -eq [Inventor.DocumentTypeEnum]::kAssemblyDocumentObject ) {
	        $export.Options['Design_Views'] = ...
	}
}

Doing special stuff in the OnExport, by manipulating the DSD for TrueView

1
2
3
4
5
6
Open-Document -LocalFile 'C:\Vault\Designs\Acad 2015\ACADE Tutorial\DEMO02.DWG'
Export-Document -Format PDF -To C:\Temp\DEMO02.DWG.pdf -OnExport {
	param($export)

	$export.DsdFile.PublishExportOptions.Type=5
}