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).

What this solves: CorelDRAW ships a single stale CHM help file, mostly VBA examples, and Python is missing the cdr-prefixed constants entirely. Here every interface gets its own page with signature, parameters, working code and the traps encountered in practice.
311interfaces
32object groups
EN · 中文languages

Browse all 311 entries →Production work

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

Browse by object 32 · 311

Connection & Init 8 entries
connecting to CorelDRAW over COM
Application 13 entries
the CorelDRAW application object
Document 20 entries
documents and file handling
Page 15 entries
pages and page setup
Layer & Shapes 14 entries
layers and shape creation
Geometry & Transform 17 entries
position, size and rotation of shapes
Group / Order / Boolean 18 entries
grouping, ordering and boolean operations
Shape Appearance 11 entries
outline, fill and transparency shortcuts
Text 13 entries
artistic and paragraph text
TextRange 7 entries
character ranges inside a text object
Fill 11 entries
uniform, gradient and pattern fills
Outline 10 entries
stroke width, style and color
PowerClip 5 entries
clipping content into a frame
Fountain Fill 8 entries
linear and radial gradient fills
Pattern / Texture Fill 8 entries
pattern, texture and PostScript fills
Transparency & Blend 7 entries
opacity and merge modes
Effects 12 entries
drop shadow, blend, contour, extrude and lens
Color 10 entries
RGB, CMYK and hex color values
Curve & Node 8 entries
subpaths and nodes
Bitmap 8 entries
raster image handling
Find & Traverse 11 entries
walking the shape tree
Units & Conversion 8 entries
document units and conversion
Import / Export 9 entries
import, export, save and print
Enumerations 9 entries
VBA constants and their integer values
Object Data 6 entries
object data and document properties
Align / Distribute 8 entries
align, distribute and transform
Layer Advanced 8 entries
multi-layer and multi-page workflows
View & Performance 6 entries
display and performance switches
Events 4 entries
waiting for user interaction
Recipes 6 entries
copy-paste ready workflows
Pitfalls 12 entries
errors that fail without raising

How to use this reference

  1. Connect first. pip install pywin32, then run the bootstrap template. Nothing else works until CorelDRAW answers.
  2. Find the interface by the action. New shapes live under Layer, colors under Fill, export under Import/Export.
  3. Every example runs standalone. Paste it under if __name__ == "__main__":.
  4. 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?

Yes. Python drives the same COM object model VBA does, through 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?

No. COM automation drives an installed, licensed copy of CorelDRAW — the script attaches to the running application, it does not reimplement it. There is no headless build and no Linux build, so nothing on this site runs on a machine without CorelDRAW.

See also: Connection

Dispatch raises 0x800401F3 / "Invalid class string". What's wrong?

Nearly always the ProgID string, not permissions. "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?

COM was never initialised on the thread doing the calling. Put 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?

You're issuing commands faster than CorelDRAW can redraw. It's a single-threaded STA server, so a command that lands mid-redraw comes back as a busy error or a hung UI. Wait 0.2 s after a property change, 0.5 s after importing an image, 0.3 s after changing a font — fonts land slowly, and a shorter wait reads the old value and reports a false failure.

See also: No sleep → hangs · Throttling

I set the font name and nothing happens — no error either.

This is the silent failure the API is known for. A misspelled font name is accepted without complaint, and 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?

Find them, then set them through the character range. 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?

Go through 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.

Objects inside a PowerClip have no 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?

Not by default. Python can't see the type library constants unless you generate the cache with 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?

Wrap it in an undo group: 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?

Switch the document unit first: 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.

See also: doc.Unit · SetSize · Points

Does this work with CorelDRAW on macOS?

No. Automation runs over Windows COM, and the macOS build of CorelDRAW exposes no COM server and no VBA. On a Mac you're limited to what the UI offers, or to a Windows VM with CorelDRAW installed inside it.

Which CorelDRAW versions does this reference cover?

Documented against CorelDRAW 2019, ProgID 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.

See also: Version · Enums

Batch processing hundreds of files is slow. What should I change?

Four things, in order of effect: 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

All entries

→ Open the full index (311 entries, searchable)