# encoding: utf-8
import win32com
from win32com.client import Dispatch
app = win32com.client.dynamic.Dispatch('Indesign.Application.CS5.5')
myDocument = app.ActiveDocument
pi = myDocument.pageItems
def getTypeById(id):
return app.DoScript("app.activeDocument.pageItems.itemByID(%s).getElements()[0].constructor.name;" % id,1246973031)
def myrec(grp):
for i2 in xrange(0,grp.count):
if getTypeById(grp[i2].id) == 'TextFrame':
rez = grp[i2].contents
if getTypeById(grp[i2].id) == 'Group':
rez = myrec(grp[i2].pageItems)
return rez
for i in xrange(0,pi.count):
if getTypeById(pi[i].id) == 'TextFrame':
print pi[i].contents
if getTypeById(pi[i].id) == 'Group':
print myrec(pi[i].pageItems)