I'm trying to save and close an AutoCAD application. I've tried to use .Quit()
but didn't work.
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()
How can I save and close my AutoCAD application?