How to export AutoCAD drawings to DXF using the the AutoCAD core console

AutoCAD is delivered with the AutoCAD core console where users can manipulate drawings via scripting. This was introduced in AutoCAD 2013 and is available in all AutoCAD products. The core console can be used with powerJobs Processor to export files.

Usage

To use to console you have to pass the path to the console, create a script file for saving the DXF and execute that the console . In this example we are exporting an AutoCAD drawing to DXF.

Define a workingdirectory where the file should be downloaded and where the DXF file should be exported.

Please remember to modify the path in the $accoreconsole variable to match with your AutoCAD version:

In the next section a script file is created that is later executed with the AutoCAD core console.

The Start-Process cmdlet starts the AutoCAD core console and passes following parameters:

  • The path to the AutoCAD core console
  • In /i the path to the parent file is passed
  • In /s the path to the newly created script file is passed and is then executed in the AutoCAD core console.

After the AutoCAD core console is executed there is a check if the DXF file exists in the specified location.

At the end of the script the script file is removed from the workingdirectory

#Get the parent file
$workingDirectory = "C:\Temp\$($file._Name)"
$localDXFfileLocation = "$workingDirectory\$($file._Name).dxf"
$vaultDXFfileLocation = $file._EntityPath +"/"+ (Split-Path -Leaf $localDXFfileLocation)
$downloadedFiles = Save-VaultFile -File $file._FullPath -DownloadDirectory $workingDirectory
$file = $downloadedFiles | select -First 1

# Change the path to match with your AutoCAD version
$accoreconsole = "C:\Program Files\Autodesk\AutoCAD [VERSION]\accoreconsole.exe"

$scriptfile = "$workingDirectory\PublishDXF.scr"

<# Values for the parameter 'DefaultFormatForSave'
1 - AutoCAD R12 DXF
13 - AutoCAD 2000 DXF
25 - AutoCAD 2004 DXF
37 - AutoCAD 2007 DXF
49 - AutoCAD 2010 DXF
#>

# create script file for accoreconsole
'(setenv "DefaultFormatForSave" "49")' | Out-File $scriptfile
'_.save "' + $localDXFfileLocation + '" ' | Out-File $scriptfile -Append

#Start the AutoCAD core console with the arguments
$p = Start-Process -FilePath $accoreconsole -ArgumentList @("/i `"$($file.LocalPath)`"", "/s `"$scriptfile`"") -Wait -NoNewWindow
$exportResult = [System.IO.File]::Exists($localDXFfileLocation)

if ($exportResult) {
# Add the DXF file to Vault
$DXFfile = Add-VaultFile -From $localDXFfileLocation -To $vaultDXFfileLocation
$file = Update-VaultFile -File $file._FullPath -AddAttachments @($DXFfile._FullPath)
}

#Clean up the workingDirectory
Clean-Up -folder $workingDirectory

Remarks