I’m trying to loop through any inline/anchored text frames in my InDesign document and copy the text within them to the end of the document. I have got as far as looping through the anchored text frames but I can’t seem to get the text content of each text frame into a variable so I can paste or duplicate the text to the end of the document. Any suggestions much appreciated!
tell application "Adobe InDesign CS3"
activate
tell active document
set mystartTextframe to text frame 1 of page 1
set myStory to parent story of mystartTextframe
-- This only gets anchored text frames (which is what I want, but not sure why it doesn't get threaded text frames as well)
set MyAnchoredObjects to (get every text frame of myStory)
repeat with oneAnchoredObject in MyAnchoredObjects
--Not Working (ideally I want to select text that is within the anchored text frame):
set MyObjectContent to contents of oneAnchoredObject
-- Then i want to move/duplicate text from within each anchored text frame to end of document - still to do.
end repeat
end tell
end tell
I now got the script copying the text from within anchored text frames. Now I’ve just got to sort out pasting it at end of document. Code so far is:
tell application "Adobe InDesign CS3"
activate
tell active document
set mystartTextframe to text frame 1 of page 1
set myStory to parent story of mystartTextframe
-- This only gets anchored text frames (which is what I want) - not sure why??!?!
set MyAnchoredObjects to (get every text frame of myStory)
repeat with oneAnchoredObject in MyAnchoredObjects
set MyObjectContent to every text of oneAnchoredObject
if MyObjectContent does not contain "" then
--Need to add code to put contents of variable at end of document/story
end if
end repeat
end tell
end tell
Finally worked it out in the end - sorry to waste people’s time with the post (but possibly it will be useful to someone else?). I am still unsure why my script only picks up anchored text frames? This is what I want but I would have thought the script I have written would pick up the threaded text frames within the story as well? I also had to convert my variable to a string to ensure it worked - not sure if this is a robust way of doing things??
tell application "Adobe InDesign CS3"
activate
tell active document
set mystartTextframe to text frame 1 of page 1
set myStory to parent story of mystartTextframe
-- loop through anchored text frames (ignoring graphics/rectangles)
-- This only gets anchored text frames which is what I want - but not sure why it works??!?!
set MyAnchoredObjects to (get every text frame of myStory)
repeat with oneAnchoredObject in MyAnchoredObjects
set MyObjectContent to every text of oneAnchoredObject
if MyObjectContent does not contain "" then
set MyObjectContent2 to MyObjectContent as string
--Place content of MyObjectContent variable plus "text box" text at end of story
set contents of insertion point -1 of myStory to "
Text Box: " & MyObjectContent2
end if
end repeat
end tell
end tell