Python connexion with AutoCad

Python connexion with AutoCad

adrien_lambertZVQMG
Observer Observer
436 Views
2 Replies
Message 1 of 3

Python connexion with AutoCad

adrien_lambertZVQMG
Observer
Observer
Dear,
 
I would like to try python automation with AutoCAD so I downloaded the trial version of AutoCad which is named : Autodesk AutoCAD 2026 - UNREGISTERED VERSION.
 
However, I cannot connect python with autocad. I get the following error message : OSError: [WinError -2147221005] running the code bellow. 
 
Could you please tell me if python automation is supported with this version of AutoCAD ? 
 
NB : I don't have admin rights on my laptop, I ran python file with both vscode and cmd
 
Kind regards,
 
Adrien
 
Code : 
import pyautocad
acad = pyautocad.Autocad()
print(acad.doc.Name)
0 Likes
437 Views
2 Replies
Replies (2)
Message 2 of 3

Moshe-A
Mentor
Mentor

@adrien_lambertZVQMG  hi,

 

maybe you'll get answers >> here << 

 

Moshe

 

0 Likes
Message 3 of 3

adrien_lambertZVQMG
Observer
Observer

Hi, 
Thanks for your answer. 
By navigating on this website I've found the name of Autocad I should use. 

 

To find it, you must do the following steps : 

1)  Press Win + R, type regedit, and hit Enter.

2) Navigate to HKEY_CLASSES_ROOT\AutoCAD.Application

3) Look for a name associated with AutoCAD Application Object in my case it is "AutoCAD.Application.25.1

4) Try the following code, AutoCAD should open now 


name_acad = "Autocad.Application.25.1"
try:
    acad = GetActiveObject(name_acad)
    print("AutoCAD is Active")
except(OSError, COMError😞 #If AutoCAD isn't running, run it
    acad = CreateObject(name_acad,dynamic=True)
    print("AutoCAD is successfuly Opened")
 
Kind regards, 
Adrien
0 Likes