[Python] Load AutoCad DWG files in Python

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    There a requirement to rendering AutoCad DWG file in Python. My first Question is,

    1:- Is is possible to render/load dwg file in python and view the file/image in python environment?

    2:- How can I do that? I tried using arcpy, but as it is a proprietary software of ArcGIS, it is not possible to directly import the library? What are the alternatives to that?

    I even explored a lot of sources on the internet but not found anything useful. Tried comtypes.client also for importing and viewing the same.

    import array
    import comtypes.client
    acad = comtypes.client.GetActiveObject("AutoCAD.Application")
    doc = acad.ActiveDocument
    ms = doc.ModelSpace
    doc.Import("sample.dwg", array.array('d', [0, 0, 0]), 1.0)


    I am getting this error, I have downloaded AutoCAD software also still I am getting this error. Please suggest what I am missing and what is the error actually means.


    OSError Traceback (most recent call last) in 3 try: ----> 4 acad = comtypes.client.GetActiveObject("AutoCAD.Application") 5 except: ~\Anaconda3\envs\py36\lib\site-packages\comtypes\client_init_.py in GetActiveObject(progid, interface, dynamic) 172 """ --> 173 clsid = comtypes.GUID.from_progid(progid) 174 if dynamic: ~\Anaconda3\envs\py36\lib\site-packages\comtypes\GUID.py in from_progid(cls, progid) 77 inst = cls() ---> 78 _CLSIDFromProgID(str(progid), byref(inst)) 79 return inst _ctypes/callproc.c in GetResult() OSError: [WinError -2147221005] Invalid class string
    ​

    Continue reading...

Compartilhe esta Página