首页/ 接口索引/ 查找与遍历

for i in range(1, coll.Count+1): s = coll.Item(i)

手工遍历。注意 CDR 集合从 1 开始,Python 的 range 要 +1。

签名

for i in range(1, coll.Count+1): s = coll.Item(i)

说明

手工遍历。注意 CDR 集合从 1 开始,Python 的 range 要 +1。

Python 示例(可直接运行)

依赖 pywin32。示例假定 app / doc / page / layer 已就绪。 见「连接与初始化」
Python
page = doc.ActivePage
shapes = page.Shapes

# 手工遍历:CDR 集合从 1 开始,Python 的 range 要 +1
for i in range(1, shapes.Count + 1):
    s = shapes.Item(i)                # s : 第 i 个形状
    print(i, "类型", s.Type, "宽", round(s.SizeWidth, 2))

关于本类:查找与遍历

CDR 的形状是树:页面 → 群组 → 容器 → 群组…。想拿到「全部文字」必须递归穿透。

同类其他接口