Start a new topic
Solved

Help with "How to use AutoCAD in powerJobs"

Trying to implement the solution provided from here: https://support.coolorange.com/support/solutions/articles/22000206915-how-to-use-autocad-in-powerjobs 


When i try to run it I get this error from it calling to the Message Filter module:  [ ERROR] - Exception calling "Register" with "0" argument(s): "Registration of MessageFilter failed, approve the registration is made in a STA Thread"


I am just learning PowerShell and PowerJobs but would be nice to interface with my knowledge of the AutoCAD API.


Any help would be great. Thanks!

-Chelsea K. 


Hello Chelsea,

have you updated your Powershell installation to the latest version? There might be issues if you are still on version 2. You can check what version you are on by typing "$PsVersionTable.PsVersion" (without the quotes) in a powershell commandline. The latest version is 5.1, but 5.0 should be fine as well. If that is not it our product support will need to take a closer look at this issue


Best regards,

Thomas

Hello Chelsea,

I just tried to reproduce this on my system and the only way I can do this is by calling


[cOCommunication.MessageFilter]::Register()  


outside of the "Invoke-Script -apartmentState STA -script" commandlet


Make sure your call of the register function is within the script block that is passed to the Invoke-Script commandlet.


Best regards,

Thomas

Thomas,

Would you be willing to explain this further or perhaps post example code? 

Thanks, 

Chelsea

Taking the example from the knowledgebase article. The script block with the green braces is executed in the Invoke-Script commandlet. In this example the Register function is called within that script block. This is fine


Invoke-Script -apartmentState STA -script {
    try {
        Open-VaultConnection
        $fileName = "Test.dwg"

        $file = Get-VaultFile -Properties @{ "File Name" = $fileName }

        Load-AutoCADMessageFilter  
        $application = New-Object -ComObject AutoCAD.Application.20 #AutoCAD 2016. For 2015 use: AutoCad.Application.19
        [cOCommunication.MessageFilter]::Register()  

        # Open ACAD document    
        $application.Documents.Open($file._FullPath)  
        #$application.Visible = $true

     } finally {
        if($application.ActiveDocument) {
            $application.ActiveDocument.Close($false) #object.Close([SaveChanges] [, FileName])
        }
        $application.Quit()
        [cOCommunication.MessageFilter]::Revoke()
        Add-Log "Closed the application."
     }
}


The described error would be caused by something like this


 [cOCommunication.MessageFilter]::Register()  

Invoke-Script -apartmentState STA -script 

    #Some code

}


Let me know if that is the case for you or if we need to analyse this further



Thomas,

I copied and pasted it fresh and then I needed to change the AutoCAD version and then also reference the local file with $file.LocalPath and somehow after some other changes got it to work!


Thank you!

Chelsea

Login or Signup to post a comment