The page items parent can be in a hierachy like
spread
page
page item
group
..........
page item
You need a recurse handler to find the parent at top of the hierachy.
Try this:
tell application "InDesign CS"
tell document 1
set myPageItemRef to object reference of page item 1
return my GetSpreadPageInfo_GivenPageItemRef(myPageItemRef)
end tell
end tell
(*
-->{
spreadIndex:1,
spreadRef:spread id 148 of document "Unbenannt-1" of application "InDesign CS",
groupIdList:{},
pageIndex:1,
pageRef:page id 153 of spread id 148 of document "Unbenannt-1" of application "InDesign CS",
pageWidth:209.999999999936,
pageHeight:296.999999999461
}
*)
on GetSpreadPageInfo_GivenPageItemRef(thisArgs)
set myMsgSubHead to "GetSpreadPageInfo_GivenPageItemRef(3000) "
--
-- returns: record, {spreadIndex:"", pageIndex:"", pageWidth:"", pageHeight:"",pageRef:{},spreadRef:{}}
--
-- thisArgs: indd object reference page item
--
try
-- GetSpreadPageInfo_GivenPageItemRef(thisArgs)
-- wird mit einem einzigen Argument thisArgs aufgerufen.
-- Bei der anschliessenden Rekursion muss ein Zwischenergebnis
-- als weiteres Argument weitergereicht werden.
-- Fuer den 2. und jeden weiteren Aufruf wird eine Liste als Argument uebergeben.
if class of thisArgs is not list then
set myObjRef to thisArgs
set myResultRec to {spreadIndex:"", spreadRef:"", groupIdList:{}, pageIndex:"", pageRef:"", pageWidth:"", pageHeight:""}
else
set myObjRef to item 1 of thisArgs
set myResultRec to item 2 of thisArgs
end if
---------------------------------------------------------------------------------------------------------
tell application "InDesign CS"
if class of myObjRef is group then
set beginning of groupIdList of myResultRec to id of myObjRef
end if
if class of myObjRef is page then
set parentClass to class of parent of myObjRef
if parentClass is spread then
set pageRef of myResultRec to myObjRef
set pageWidth of myResultRec to (item 4 of bounds of myObjRef) - (item 2 of bounds of myObjRef)
set pageHeight of myResultRec to (item 3 of bounds of myObjRef) - (item 1 of bounds of myObjRef)
set spreadIndex of myResultRec to (index of parent of myObjRef)
set spreadRef of myResultRec to (parent of myObjRef)
set pageIndex of myResultRec to (index of myObjRef)
return myResultRec
else
error "Expected that parent of page is a spread but found parent class: " & parentClass
end if
else
set newObjRef to object reference of parent of myObjRef
my GetSpreadPageInfo_GivenPageItemRef({newObjRef, myResultRec})
end if
end tell
on error errMsg number errNum from errObj partial result errPartialSuccess to errClass
error myMsgSubHead & errMsg
end try
end GetSpreadPageInfo_GivenPageItemRef
Peter