Как я могу сохранить и закрыть приложение AutoCAD с помощью python?

Я пытаюсь сохранить и закрыть приложение AutoCAD. Я пытался использовать .Quit(), но не получилось.

from comtypes import COMError
from comtypes.client import CreateObject, GetActiveObject


def main():
    # Capture opened AutoCAD
    try:
        acad = GetActiveObject("AutoCAD.Application")

    # Open new AutoCAD instance
    except (OSError, COMError):
        acad = CreateObject("AutoCAD.Application", dynamic=True)

    # Path to dwg file
    filepath = r"C:\test.dwg"  # Replace it with the actual drawing path
    doc = acad.Documents.Open(filepath)

    load_lisp = '(load "C:/DemoExtracao.fas") '  # Notice that the last SPACE is equivalent to

    doc.SendCommand(load_lisp)

    execute_lisp = "(DEMO) "

    doc.SendCommand(execute_lisp)
    
    doc.Quit() # This line doesn't work


# Início da aplicação principal
if __name__ == "__main__":
    main()

Как сохранить и закрыть приложение AutoCAD?


person Henrique Branco    schedule 01.09.2020    source источник
comment
Использование python win32com: Сохранение файлов AutoCAD (.dwg) с помощью Python. В ответе также есть ссылки на документацию по программированию AutoCad.   -  person Trenton McKinney    schedule 01.09.2020
comment
А как насчет закрытия приложения AutoCAD? На этот вопрос выше я мог просто сохранить как и сохранить AutoCAD... =(   -  person Henrique Branco    schedule 01.09.2020
comment
Этот метод хорошо работает в VBA, но не работает в Python.   -  person Henrique Branco    schedule 02.09.2020