Home/ Reference/ Find & Traverse

coll.FindShapes("@fill.color='#FF0000'", 0, True)

Search by property condition, SQL-ish syntax. It cuts the amount of data coming back, but field names and syntax vary by version — start with a simple condition.

Signature

coll.FindShapes("@fill.color='#FF0000'", 0, True)

Notes

Search by property condition, SQL-ish syntax. It cuts the amount of data coming back, but field names and syntax vary by version — start with a simple condition.

Python example (runnable)

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

# query by property, SQL-like. Field names shift by version, start simple
try:
    reds = page.FindShapes("@fill.color='#FF0000'", 0, True)   # 0 = any type
    print("Red shapes: ", reds.Count)
except Exception as e:
    # when the query syntax is unsupported, filter in Python instead (slower, always works)
    print("Query failed, filtering by walking instead: ", e)
    cnt = 0
    for i in range(1, page.Shapes.Count + 1):
        s = page.Shapes.Item(i)
        try:
            if (s.Fill.UniformColor.HexValue or "").upper() == "#FF0000":
                cnt += 1
        except Exception:
            pass
    print("Red shapes, found by walking: ", cnt)

About this section: Find & Traverse

Find & Traverse — walking the shape tree.

Other entries in this section