Home/ Reference/ Find & Traverse

shape.Type == 7 → shape.Shapes

Test for a group, then descend. Cap the recursion depth (8 levels in the code) to survive pathological nesting.

Signature

shape.Type == 7 → shape.Shapes

Notes

Test for a group, then descend. Cap the recursion depth (8 levels in the code) to survive pathological nesting.

Python example (runnable)

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

# go one group level deep
for i in range(1, page.Shapes.Count + 1):
    s = page.Shapes.Item(i)

    try:
        is_group = (s.Type == 7)
    except Exception:
        is_group = False

    if not is_group:
        continue

    print("Group", i, "has", s.Shapes.Count, " member(s)")
    for k in range(1, s.Shapes.Count + 1):
        child = s.Shapes.Item(k)      # child : the k-th member of the group
        print("   member", k, "type", child.Type)

About this section: Find & Traverse

Find & Traverse — walking the shape tree.

Other entries in this section