# Export-Document ```{toctree} :glob: :hidden: export-document/* ``` Exports the document in the specified format. ## Syntax ```{code-block} PowerShell :linenos: Export-Document -To [-Format ] [-Options ] [-Document ] [-OnExport ] [] ``` ## Parameters | Type | Name | Description | Optional | | ------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | String | To | Location where the converted file should be saved | no | | String | Format | File extensions:[PDF](/jobprocessor/code_reference/cmdlets/export-document/pdf), [DWF / DWFX](/jobprocessor/code_reference/cmdlets/export-document/dwf_dwfx) , [IGES](/jobprocessor/code_reference/cmdlets/export-document/iges) , [STEP](/jobprocessor/code_reference/cmdlets/export-document/step) , [DXF](/jobprocessor/code_reference/cmdlets/export-document/dxf) , [DWG](/jobprocessor/code_reference/cmdlets/export-document/dwg) , [GIF](/jobprocessor/code_reference/cmdlets/export-document/gif) , [BMP](/jobprocessor/code_reference/cmdlets/export-document/bmp) , [TIFF](/jobprocessor/code_reference/cmdlets/export-document/tiff) , [PNG](/jobprocessor/code_reference/cmdlets/export-document/png) , [JPEG](/jobprocessor/code_reference/cmdlets/export-document/jpeg).
If not specified a freestyleExport will be used, where you have to place your export logic in -OnExport | yes | | Hashtable / String | Options | The document will be exported with the passed options, or configuration Files | yes | | {ref}`IDocument ` | Document | The cmdlet will export this document, otherwise the last opened document will be exported | yes | | Scriptblock / String | OnExport | The Scriptblock 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 Scriptblock, 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: ```{eval-rst} .. csv-table:: :header: "Type", "Name", "Description", "Access type" "string", "Name", "The name of the export is the fromat that you pass to the cmdlet", "read-only" ":ref:`IApplication `", "Application", "The application which is used for the export.", "read-only" ":ref:`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: {doc}`PDF `, {doc}`DWF/DWFx `, {doc}`DWG `, {doc}`DXF `, {doc}`IGES `, {doc}`STEP `,\ {doc}`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: {doc}`DWG `, {doc}`DXF `\ {doc}`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: {doc}`BMP `, {doc}`GIF `, {doc}`JPEG `, {doc}`PNG `, {doc}`TIFF `\ {doc}`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: {doc}`PDF `, {doc}`DWF/DWFx `\ {doc}`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 PDF with default options** ```PowerShell Open-Document -LocalFile 'C:\Vault\AutoCad\Test.dwg' Export-Document -format PDF -To C:\Temp\Test.pdf ``` **Exporting with Options** ```{code-block} PowerShell :linenos: 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** ```{code-block} PowerShell :linenos: $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** ```{code-block} PowerShell :linenos: $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** ```{code-block} PowerShell :linenos: $result = Export-Document -format PDF -To C:\Temp\Test.pdf if($result.Application.Name -eq 'Inventor') { $result.Document.Instance #... } ``` **Handling exceptions thrown in OnExport scriptBlock** ```{code-block} PowerShell :linenos: $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 scriptBlock** ```{code-block} PowerShell :linenos: 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** ```{code-block} PowerShell :linenos: 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** ```{code-block} PowerShell :linenos: 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 } ```