Start a new topic
Solved

Reading properties from AutoCad DWG by using API

Hello,


I like to read out an AutoCAD property and want to realize it during AutoCAD API.

I tried to realize it according the following description:

how-to-use-autocad-in-powerjobs


I also update my powershell Version to 5.1. But If I start the Job I always get the following error Messages:

11:14:07: [ FATAL] - Execute failed with exception
11:14:07: [ ERROR] - You cannot call a method on a null-valued expression.


How can I fix this issue?

Thanks for your help!



Hello Martin,

Which property are you trying to read?

Can you please show me the code that you used?


Kind regards,

Manuel Cassan

Hi Manuel,


I try to read out an user defined property.


I used the following code:


 

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()
        Write-Host "Closed the application."
     }
}

 



I have a solution for my Problem:

The Code: "Open-VaultConnection" sould not be insert the Invoke-Script. Now I can open AutoCAD via API!


Do you have an how I can now read out the iproperties?


Regards

Martin


Hello Martin,

Is there a specific reason why this is done using the API?

The properties can be read using e.g Get-VaultFile. The file object will have the properties.


Kind regards,

Manuel Cassan

Manuel,


Ok, I try to do it in your way.Thanks.


One questions: Can you tell me how I can get the linked Item of a file?


This would be great!

Thanks!


Hello Martin,

You can use the Vault API to get the item linked to a file. First you can get the file using e.g. Get-VaultFile then use the Id to get the item:

$vault.ItemService.GetItemsByFileId(FileId)


Kind regards,

Manuel Cassan

Hi Manuel,


thank you. I could fix my Problem and now my code works. Fine!


I have one last question about reading user definded properties.

A System property I can read out in the follwing way:

$systemproperty_Title=  $file.Title


If I create a user property, the System Name is something like this:

 7b3c3cf7-22c3-40bc-83dd-6503d2178fcf

How can I read out this property?


Thank you for helping!

Martin


Hi Martin,

The property  can be accessed trough the DispName. 


Kind regards,

Manuel Cassan


1 person likes this
Login or Signup to post a comment