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 & InitPython
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.
- This section has 11 entries; this is one of them.
- See the full section index: Find & Traverse
Other entries in this section
- coll.FindShapes(query, shapeType, recursive)The main search call. query is a string condition (empty means anythin
- coll.FindShapes("", 6, True)Every text object. The most-used call of the lot, and it drills throug
- coll.FindShapes("", 7, True)Every group. When a document is huge, searching only the current level
- coll.FindShapes("", 5, True)Every bitmap.
- coll.FindShapes("", 3, True)Every curve.
- coll.FindShapes("@fill.color='#FF0000'", 0, True)Search by property condition, SQL-ish syntax. It cuts the amount of da
- for i in range(1, coll.Count+1): s = coll.Item(i)Manual iteration. Remember that CDR collections start at 1, so Python'
- shape.PowerClip → .ShapesContainer descent. Containers can sit inside containers, so push those