311 interfaces · each with a runnable pywin32 example
CorelDRAW × Python COM Reference
Driving CorelDRAW from Python, documented entry by entry: 311 interfaces, each with its signature, real-world notes and a runnable example. Verified against CorelDRAW 2019 (V21).
cdr-prefixed constants entirely. Here every interface gets its own page with signature, parameters, working code and the traps encountered in practice.Work we take on
Beyond this reference, we take on production work
For print, signage and e-commerce teams. Quoted per job, English or Chinese.
Services and contact →Email 281786770@qq.com · WeChat yinjia823
Start here: connect to CorelDRAW
- General bootstrap template — run this first Connects to CorelDRAW and gets doc / page / layer; the base for the other entries.
- pythoncom.CoInitialize()COM initialization; it goes on the first line of the script. Any thread that touches COM has to call it again, or you get "CoInitialize has not been called". Pair it with pythoncom.CoUninitialize() at the end.
- win32com.client.Dispatch("CorelDRAW.Application.21")Connect by version number; 21 is CorelDRAW 2019. If CDR is already running this attaches to that process, otherwise it starts a new one.
- app.Visible = TrueShows the CDR window. Setting it False is faster for batch runs, but keep it True while debugging so you can see what actually happened.
- win32com.client.Dispatch("CorelDRAW.Application")No version number, so it binds to whatever version is registered as default. On a machine with several versions installed you may not get the one you wanted.
- win32com.client.GetActiveObject("CorelDRAW.Application.21")Attaches to an instance that is already open and never starts a new process. It raises if CDR isn't running, which makes it the right call for "open CDR by hand first, then run the script".
- win32com.client.gencache.EnsureDispatch(progid)Once the constant cache exists you can write cdrTextShape instead of 6. Generating the CorelDRAW type library fails now and then (permissions, version conflicts); when it does, fall back to dynamic.Dispatch and use the numeric constants.
- app.VersionReturns the version as a string. Use it to confirm which version you actually connected to.
- 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.
Browse by object 32 · 311
How to use this reference
- Connect first.
pip install pywin32, then run the bootstrap template. Nothing else works until CorelDRAW answers. - Find the interface by the action. New shapes live under Layer, colors under Fill, export under Import/Export.
- Every example runs standalone. Paste it under
if __name__ == "__main__":. - Errors go to the Pitfalls section first.
CoInitialize not called, silent font failures and stale references are all documented there.
FAQ
These are the problems that actually come up when you drive CorelDRAW from Python. Every answer points to the reference page that covers it.
Can I automate CorelDRAW from Python instead of VBA?
pywin32, so every property and method in the CorelDRAW type library is reachable from a .py file. What you trade: you lose the macro recorder and the VBA object browser, and gain a real editor, version control and pip packages.See also: Dispatch · Start here
Does this work without CorelDRAW installed?
See also: Connection
Dispatch raises 0x800401F3 / "Invalid class string". What's wrong?
"CorelDRAW.Application.21" carries the internal version number — 21 is CorelDRAW 2019 — not the year, so .2019 fails. If the number is right, CorelDRAW isn't registered for the account running the script, or isn't installed at all.See also: Dispatch · Dispatch without version
"CoInitialize has not been called" — why?
pythoncom.CoInitialize() on the first line, and call it again inside every worker thread — COM initialisation is per-thread, not per-process. Pair it with CoUninitialize() when that thread ends.See also: CoInitialize
The script freezes CorelDRAW, or returns 0x8001010A (server busy). Why?
See also: No sleep → hangs · Throttling
I set the font name and nothing happens — no error either.
Text.FontProperties swallows size changes entirely. Read the value back and compare before continuing, and never call ConvertToCurves() until the read-back matches — converting bakes the wrong font in permanently.See also: Wrong font name · FontProperties
How do I change the font or size of every text object in a document?
layer.FindShapes("", 6, True) returns all text including anything nested in groups and PowerClips, and the whole run is shape.Text.Story.Characters.All. Setting the font on Story.FontProperties instead does nothing at all.See also: FindShapes text · Characters.All
How do I read or edit text that is inside a PowerClip?
shape.PowerClip.Shapes and search that collection — you don't have to enter edit mode. shape.PowerClip.Shapes.FindShapes("", 6, True) returns the text inside. Check for None first: PowerClip on a shape that isn't a container returns nothing.See also: PowerClip.Shapes · PowerClip
shape.Left raises an exception for shapes inside a container.
Left or Top. Use shape.GetBoundingBox(), which returns (x, y, w, h) and works at any nesting depth. The same applies to the children of a group.See also: GetBoundingBox · No Left/Top
Can Python use the VBA constants, like cdrAlignLeft?
gencache.EnsureDispatch; without it you pass numbers. And those numbers are not consecutive — Fill.Type jumps 3 → 8, because 5, 6 and 7 don't exist.See also: EnsureDispatch · Enums
How do I make a long batch job undo in one step?
doc.BeginCommandGroup("batch") before the loop and doc.EndCommandGroup() after it. Put the End call in a finally block — an exception that skips it leaves CorelDRAW stuck inside the group, and every later command piles into it.See also: BeginCommandGroup · Unclosed undo group
How do I export a print-ready PDF from a script?
doc.PublishToPDF(path) with the defaults is the reliable route. Two things it will not fix for you: check page.Bleed is at least 3 mm, and check bitmaps are CMYK at 300 dpi before exporting.See also: PublishToPDF · Bitmap.Mode
How do I set the page size in millimetres?
doc.Unit = cdrMillimeter, then page.SetSize(210, 297) means millimetres. Every geometric API follows doc.Unit, with one exception — font sizes are always points, whatever the document unit says.Does this work with CorelDRAW on macOS?
Which CorelDRAW versions does this reference cover?
21. The object model has been stable across many releases, but enum values drift between versions, so read them instead of hardcoding. To find out which copy you actually attached to, read app.Version.Batch processing hundreds of files is slow. What should I change?
app.Visible = False, app.Optimization = True to stop redraws, move saving out of the loop so it happens once at the end, and keep the sleeps only where they're actually needed. Reset Optimization when you finish, or the window looks frozen afterwards.See also: Save outside the loop · Optimization