I want to open existing dwg or dxf file with python in my prompt

Viewed 588

I want to make an python script to extract information of existing dwg/dxf file. I thought pyautocad can help me, but I cannot find correct way to do this.

I heard that pyautocad use AutoCAD ActiveX so try to use Open method of AutoCAD ActiveX (Here https://help.autodesk.com/view/OARX/2018/HUN/?guid=GUID-9ED7A548-7978-4BFD-8462-E2FA747E8880)

But it said this method should be used in MDI mode...

Then what can i try to open existing dwg/dxf file with python??



from pyautocad import Autocad

acad = Autocad(create_if_not_exists=True)
print(acad.doc.Name) #for test

acad2 = acad.doc.Open('Test.dwg') #I want to open saved dwg or dxf file of my computer
print(acad2.doc.Name)

print('Quit')


1 Answers

I do not use Python but have a little knowledge of the AutoCAD COM/ActiveX API. Try like this:

acad2 = acad.Documents.Open('Test.dwg')
Related