Home/ Reference/ Find & Traverse

coll.Count

Element count for the collection. More reliable than len(coll), which doesn't always work on COM collections in Python.

Signature

coll.Count

Notes

Element count for the collection. More reliable than len(coll), which doesn't always work on COM collections in Python.

Python example (runnable)

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

texts = page.FindShapes("", 6, True)
n = texts.Count                       # Count is the element count

print("Total text shapes: ", n)

if n == 0:
    print("No text found, skipping the rest")

# do not use len(texts); COM collections do not always support it

About this section: Find & Traverse

Find & Traverse — walking the shape tree.

Other entries in this section