app.Quit()
Closes CorelDRAW entirely. Don't call it at the end of a batch job — it takes the user's unsaved documents with it. doc.Close() is safer.
Signature
Notes
doc.Close() is safer.Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initimport time
# Quit CorelDRAW entirely. Dangerous: unsaved user documents go with it
# Safer: close each document in reverse order first (saving if needed)
for i in range(app.Documents.Count, 0, -1): # reverse order so indexes do not shift under you
d = app.Documents.Item(i) # d : the i-th document
if d.Dirty: # Dirty=True means unsaved changes
d.Save()
d.Close() # close the document, keep the app running
app.Quit() # quit CorelDRAW last
print("Quit")
What Quit actually means
app.Quit() exits the whole CorelDRAW application, it does not close a document. It
closes every open document, including the ones somebody else is editing. That is why it is the most
easily misused call in this reference — the tutorial line "and don't forget app.Quit() at
the end" has caused a lot of damage.
Answer one question first: who started this instance
That is the only criterion. Code style and best practices are irrelevant:
- Your script started it (CorelDRAW was closed beforehand): quit it. Otherwise you leave orphan processes behind, and a debugging session piles up a dozen of them at several hundred megabytes each.
- You attached to the user's open instance: never quit. The user may have three documents open, one unsaved. One Quit call raises a "save changes?" dialog — and an unattended script then waits there forever.
To clean up, close only the documents you created. Decide this before you write the code, because the structure of everything that follows depends on the answer.
The process may survive Quit
Quit is a request, not an immediate termination. If COM references are still held — your
Python variable still points at app, at a doc, or at a shape pulled out of a
collection — the process stays alive in the background.
A genuinely clean shutdown is three steps: call Quit, release the references, confirm the process is gone:
import time
import pythoncom
def shutdown(app, doc=None, timeout=20):
# close the document first; letting Quit do it can raise a dialog
try:
if doc is not None:
doc.Close()
except pythoncom.com_error:
pass
try:
app.Quit()
except pythoncom.com_error as e:
# the user may have closed it already; that is not an error
print("already disconnected while quitting:", e.args[1])
del doc
del app # the important line: drop the COM reference
time.sleep(1) # give it a moment to actually exit
Note the del app. Plenty of people call Quit, never release the reference, and then
complain that Task Manager is full of CorelDRW.exe.
What happens if you touch app after Quit
You do not get a polite "already closed". You get a COM error whose text is roughly "the object has
been disconnected from its clients", HRESULT 0x80010108 (RPC_E_DISCONNECTED). When you see
that code, check whether you tried to read a property for logging after quitting — that is the most
common self-inflicted case.
So: write down everything you need before Quit. Version, document count, durations, failure list — all of it goes to disk while the object is still alive.
A safer pattern for batch work
In a batch job over hundreds of files, the thing that matters is not Quit, it is closing each document cleanly. The order that holds up:
- After each document: export,
doc.Close(), drop the doc variable. Do not let dozens of document objects accumulate; memory climbs the whole way. - After the loop: one
app.Quit(), and only if your script started the instance. - On failure mid-run: wrap in try/finally so Quit still happens, otherwise the failed job leaves a process behind.
One real caveat about doc.Close(): if the document is flagged as modified, closing may
ask whether to save. A batch job should never reach that point — your output is already exported to a
file. If it is still asking, the pipeline is missing an export step or mutating the document without
saving. That is a design problem, not a closing-technique problem.
When Quit is the right call and Close is not
The reverse case exists too: the script creates a temporary instance for one job and the instance should disappear afterwards. Closing documents one by one is just extra work there — Quit is cleaner. The criterion is unchanged: who owns the instance. Owner, Quit. Guest, Close.
About this section: Connection & Init
Connection & Init — connecting to CorelDRAW over COM.
- This section has 8 entries; this is one of them.
- See the full section index: Connection & Init
Other entries in this section
- pythoncom.CoInitialize()COM initialization; it goes on the first line of the script. Any threa
- win32com.client.Dispatch("CorelDRAW.Application.21")Connect by version number; 21 is CorelDRAW 2019. If CDR is already run
- app.Visible = TrueShows the CDR window. Setting it False is faster for batch runs, but k
- win32com.client.Dispatch("CorelDRAW.Application")No version number, so it binds to whatever version is registered as de
- win32com.client.GetActiveObject("CorelDRAW.Application.21")Attaches to an instance that is already open and never starts a new pr
- win32com.client.gencache.EnsureDispatch(progid)Once the constant cache exists you can write cdrTextShape instead of 6
- app.VersionReturns the version as a string. Use it to confirm which version you a