Home/ Reference/ Recipes

Batch undo group

Wrap big jobs in BeginCommandGroup / EndCommandGroup and one Ctrl+Z in CDR undoes the whole thing.

Scenario

Batch undo group

Notes

Wrap big jobs in BeginCommandGroup / EndCommandGroup and one Ctrl+Z in CDR undoes the whole thing.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
doc.BeginCommandGroup("Generate 20 pages")
try:
    layer = doc.ActivePage.ActiveLayer
    for i in range(20):
        layer.CreateRectangle2(0, i * 10/25.4, 50/25.4, 8/25.4)
finally:
    doc.EndCommandGroup()            # must sit in finally so errors still close it

print("Done; a single Ctrl+Z undoes the whole batch")

About this section: Recipes

Recipes — copy-paste ready workflows.

Other entries in this section