Home/ Reference/ Pitfalls

Objects inside containers have no Left/Top

Reading Left/Top on a shape inside a PowerClip raises. GetBoundingBox() is the only way in.

Symptom

Objects inside containers have no Left/Top

Notes

Reading Left/Top on a shape inside a PowerClip raises. GetBoundingBox() is the only way in.

Python example (runnable)

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

# shapes in a container have no Left/Top; reading them raises, use GetBoundingBox
for i in range(1, page.Shapes.Count + 1):
    s = page.Shapes.Item(i)
    try:
        pc = s.PowerClip
    except Exception:
        pc = None
    if pc is None:
        continue

    for k in range(1, pc.Shapes.Count + 1):
        inner = pc.Shapes.Item(k)
        x, y, w, h = inner.GetBoundingBox()     # the only position read that works
        print("Shape position inside the container: ", round(x, 2), round(y, 2))

About this section: Pitfalls

Pitfalls — errors that fail without raising.

Other entries in this section