Start a new topic

export-document (dxf files to overwrite existing files)

How do I invoke a command to overwrite existing files without a dialog always popping out when exporting a dxf file.


e.g. within the dxf_2d.ini file the All Sheets is set to Yes.


This means that all layouts are exported as dxf files into the required location.


If the files have previously been generated. On another export a dialog pops out to save each file.


How to stop this?


Command:

$exportResult = Export-Document -Format 'DXF' -To $localDXFfileLocation -Options $configFile


Within the ini file:

ALL SHEETS=Yes


Thanks for any help

Paul


1 Comment

Hello Paul,

this is probably because your destination file is read-only flagged. It is a good practice to export your PDF to a local temporary location and move it from there if you need it on a network drive. The Powershell move and copy command have a switch to override read-only files. Also it makes it easier to find issues like your current one as you can first check if the PDF is created locally. If it is you have an issue with the copy function. If it isn't you have an issue with the PDF creation.

If you are using a local path already there might have been issues deleting the temporary files. In that case just delete them manually one time and make sure you have a cleanup routine in your script in case there is an error in the script.


The following example was tested with Powershell 5. If you are using an older version things might work differently. It demonstrates how to export to a localpath and copy the files afterwards. 


Example:

  

#...
$destinationDirectory = "C:\TEMP\COPYTEST"
$openResult = Open-Document -LocalFile $file.LocalPath -Options @{ FastOpen = $fastOpen }
if($openResult) {
   if($file._Extension -eq "ipt") {
        $configFile = "$($env:POWERJOBS_MODULESDIR)Export\DXF_SheetMetal.ini" 
   } else {
        $configFile = "$($env:POWERJOBS_MODULESDIR)Export\DXF_2D.ini" 
   } 
   $exportResult = Export-Document -Format 'DXF' -To $localDXFfileLocation -Options $configFile 
   if($exportResult) {
        $escpaedFilename = [regex]::Escape([System.IO.Path]::GetFileNameWithoutExtension($localDXFfileLocation))
        $localDXFfiles = Get-ChildItem -Path (split-path -path $localDXFfileLocation) | Where-Object { $_.Name -match '^'+$escpaedFilename+'.*(.dxf|.zip)$' }
        if(-not (Test-Path $destinationDirectory)) {
            $destinationDirectory = New-Item -Path $destinationDirectory -ItemType:Directory
        }
        foreach($dxf in $localDXFfiles) {
            Copy-Item -Path $dxf.FullName -Destination $destinationDirectory -Force
        }
   } 
   $closeResult = Close-Document
}
#...

  


Best regards,

Thomas


Login or Signup to post a comment