Per default powerJobs Processor uses DWGTrueView to generate files out of AutoCAD drawings. DWGTrueView is able to export only PDF and DWF files. When other file formats are required it is necessary to use AutoCAD. The AutoCAD API runs in a single threaded apartment(STA). In order for a thread, this means a job, to be able to communicate with it it must run in a STA as well. However powerJobs Processor starts the PowerShell runspace in a multi threaded apartment(MTA).


To be able to have a stable communication with the AutoCAD API some messagefilters need to be used. Without these you will get random COM Exceptions.


  • Download from the attachments
  • Make sure the files are Unblocked
  • Copy all files from the archive in your powerJobs Modules folder at "C:\ProgramData\coolOrange\powerJobs\Modules"
  • Make sure the Windows user that will run powerJobs Processor has permissions to add, edit and delete files in the powerJobs Processor modules folder

Using the Modules

The module AutoCAD.Helper.psm1 loads the latest AutoCAD assembly and does the communication with the AutoCAD API for you. The MessageFilter.psm1 and InvokeApartmentstate.psm1 are used for the communication with the AutoCAD API.

  • Before you can use the message filters you have to add them to the current runspace. Call the function Load-AutoCADMessageFilter to do that.
  • The fully qualified name of the class is cOCommunication.MessageFilter and it contains to static methods Register() and Revoke()
  • You always have to call the Register() method before you use any AutoCAD API call.
  • You always have to call the Revoke() method after you used your last AutoCAD API call.
  • You can open a new AutoCAD instance with the New-Object commandlet.


This example shows how to export a DXF from an AutoCAD file using the provided modules. This can be added to your job to create a DXF file out of an AutoCAD drawing. The sample has to be inserted at least after the Save-VaultFile cmdlet if you are modifying a sample job delivered with powerJobs Processor.

Invoke-Script -apartmentState STA -script {
    try {
        $Application = Start-AutoCAD
        $Application.Visible = 0

        $Document = $Application.Documents.Open($file.LocalPath)
        $Document.SaveAs($localDXFfileLocation, [Autodesk.AutoCAD.Interop.Common.AcSaveAsType]::ac2000_dxf, $null)

        if( -not ([System.IO.File]::Exists($localDXFfileLocation)) ) {
            throw $Error[0]

        $DXFfile = Add-VaultFile -From $localDXFfileLocation -To $vaultDXFfileLocation -FileClassification None -Hidden $hideDXF
        $file = Update-VaultFile -File $file._FullPath -AddAttachments @($DXFfile._FullPath)
    catch {
        throw "Error in Script! message: '$($Error[0])'"
    finally {


  • As the Invoke-Script Cmdlet creates a new thread within your current runspace you'll have access to all the objects and variables that were declared before calling it.
  • Please note that we cannot offer support for the AutoCAD API in the scope of product support, but you can post any questions in our forum if you want. If you need one of our supporters to work out a solution you will need a support card.
  • If you are using Powershell 2 you will have issues accessing the AutoCAD API without reflection. You should update the the latest version.

See Also

Add a job on lifecycle transition (coolOrange knowledge base)