Home/ Reference/ Pitfalls

Collection indexes start at 1

Pages.Item(1) is the first page. In Python that means range(1, n+1).

Symptom

Collection indexes start at 1

Notes

Pages.Item(1) is the first page. In Python that means range(1, n+1).

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
page = doc.ActivePage

# CorelDRAW is 1-based: the first element is Item(1), not Item(0)
first = doc.Pages.Item(1)
print("First page width: ", first.SizeWidth)

for i in range(1, page.Shapes.Count + 1):     # note the +1
    s = page.Shapes.Item(i)
    print(i, s.Type)

About this section: Pitfalls

Pitfalls — errors that fail without raising.

Other entries in this section