Export-Document

Exports the document in the specified format.

Export-Document -To <String> [-Format <String>] [-Options <Object>] [-Document <IDocument>] [-OnExport <Scriptblock>] [<CommonParameters>]

Type Name Description Optional
String To Location where the converted file should be savedno
String Format File extensions:PDF, DWF / DWFx, IGES, STEP,DXF, DWG, GIF, BMP, TIFF, PNG, JPEG. If not specified a freestyleExport will be used, where you have to place your export logic in -OnExportyes
Hashtable / String Options The document will be exported with the passed options, or configuration Filesyes
IDocument Document The cmdlet will export this document, otherwise the last opened document will be exportedyes
Scriptblock / String OnExportThe scriptblock/function will be executed after collecting the options but before the real export startsyes

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

When passing invalid -Options the export will not fail, in that case the default settings will be used.
For -OnExport it is either possible to pass a function name or a scriptblock which then will be executed at runtime.


The parameters in scriptblock OnExport are: $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:

TypeNameDescriptionAccess type
string NameThe name of the export is the fromat that you pass to the cmdletread-only
IApplication ApplicationThe application which is used for the export.read-only
IDocument SourceDocumentThe document that will be exportedread-only
IFileInfo DestinationFileThe output location and name that was passed to the cmdletread-only
ExportSettings SettingsThe exporting options that are used for the export. ExportSettings.Options real HashTable entiries of -Optionsread-write
HashSet<string> SupportedDocumentTypesConatins all the supported input formats of the exportread-write

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:

TypeNameDescriptionAccess type
string TranslatorNameThe ID of the translator that is used. Usually this is a GUIDread-write
TranslatorAddInTranslatorAddinRepresents the Inventor API TranslatorAddin object. By default it is created by using the TranslatorName read-write
TranslationContextContextRepresents the Inventor API TranslationContext. By default a new one is created with Type IOMechanismEnum.kFileBrowseIOMechanismread-write
Hashtable OptionsRepresents 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 Trueread-write
DataMedium DataMediumRepresents the Inventor API DataMedium. By default FileName is set to the destination file from -To argumentread-write

DataIO

Exports: DWG, DXF
Application: Inventor, InventorServer

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

TypeNameDescriptionAccess type
string FormatThe first options part for DataIO export, e.g. FLAT PATTERN DWG?…read
SheetMetalComponentDefinition SheetMetalComponentDefinitionRepresents the Inventor API SheetMetalComponentDefinition read-write
boolUnfoldwhen set to True, the SheetMetal will be unfold. By default it is set to !HasFlatPatternread-write
DataIODataRepresents the Inventor API DataIO object. It is the DataIO value of the SheetMetalComponentDefinitionread
Hashtable OptionsRepresents 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_BENDread-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.

TypeNameDescriptionAccess type
FileInfoDSDFileThis property exposes multitple properties which allow you to easy manipulate the dsd fileread-write

Exporting the last opened document to PDF with default options

Open-Document -LocalFile 'C:\Vault\AutoCad\Test.dwg'
Export-Document -format PDF -To C:\Temp\Test.pdf

Exporting with Options

Export-Document -format DXF -To C:\Temp\Test.dxf -Options C:\Temp\test.ini
Export-Document -format DXF -To C:\Temp\Test.dxf -Options @{'dpi resolution'='50000px'}

Exporting multiple documents

$openPartDocument = Open-Document -LocalFile 'C:\Vault\Designs\Padlock\External\Case Back.ipt'
$openAssemblyDocument = Open-Document -LocalFile 'C:\Vault\Designs\Padlock\Assemblies\Pad Lock.iam'
Export-Document -Document $openPartDocument.Document -format JPEG -To C:\Temp\Case Back.jpg
Export-Document -Document $openAssemblyDocument.Document -format BMP -To C:\Temp\Pad Lock.bmp

Validating Export result

$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

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

Exporting with even more possibilities in OnExport scriptBlock

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

Open-Document -LocalFile 'C:\Vault\Designs\Padlock\Assemblies\Pad Lock.iam'
$result = Export-Document -Format DWF -To C:\Temp\Test.dwf -Options -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

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
}