S
S
Sergey Svetlov2020-08-27 11:14:00
Python
Sergey Svetlov, 2020-08-27 11:14:00

Python: Reading and writing DWG files, how?

There is a task to automate a routine process related to Autocad 2020 LT. It is necessary to insert the same table into 180 DWG files (it is not a problem to load it into Python). The method to open the file does not work:

from pyautocad import Autocad, APoint
acad = Autocad()
acad.prompt("Hello, Autocad from Python\n")
print(acad.doc.Name)

The code throws an error:
---------------------------------------------------------------------------
    OSError                                   Traceback (most recent call last)
    (много всякой и)
    OSError: [WinError -2147221021] **Операция недоступна**


Does anyone know how to correctly access and write to a DWG file in python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2020-08-27
@svetloffs

1.Dwg (not to be confused with DXF) is a closed and binary format. and it is very problematic to directly interact with it without a CAD program.
2. There is no API in AutoCAD LT version. those. you will not be able to execute any third party code in LT.
Options:
1. Use some CAD and its API (python is unlikely, usually C#).
2. Convert everything to dxf and use this library
3. and quite exotic way - RPA software.
The first option is the most reasonable, and trials are enough for the task. (If one-time).
however, you will have to learn the API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question