Home/ Reference/ Pitfalls

Unclosed undo group freezes CorelDRAW

If an exception escapes after BeginCommandGroup, CDR stays stuck inside the group. Put EndCommandGroup in a finally block.

Symptom

Unclosed undo group freezes CorelDRAW

Notes

If an exception escapes after BeginCommandGroup, CDR stays stuck inside the group. Put EndCommandGroup in a finally block.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
doc.BeginCommandGroup("safe pattern")
try:
    layer = doc.ActivePage.ActiveLayer
    layer.CreateRectangle2(0, 0, 50/25.4, 50/25.4)
    # if this raises...
finally:
    doc.EndCommandGroup()            # close it no matter what, or CorelDRAW stays stuck in the group
print("Undo group closed safely")

About this section: Pitfalls

Pitfalls — errors that fail without raising.

Other entries in this section