I need to iterate through each text frame that can be found on one layer of an ID document.
Here’s the basics:
tell application "Adobe InDesign CS3"
-- get count of text frames of layer "Laser" of page 1 of document 1 -->>does not work but what I want
--get count of text frames of page 1 of document 1 -->>works but not helpful
get count of text frames of layer "Laser" -->>does not work
end tell
Looking at the dictionary, text frames are contained by the layer, page and the document. Even if I tell the “Laser” layer, I cannot get the count of its text frames.
For each text frame I find on this particular layer, on each page, I need to make a duplicate, which is why I cannot seem to use an “every” statement.
I keep having trouble with “every” clauses in Indesign anyway, thanx, sam
This would be the basic form of going through each of those text frames:
tell application "Adobe InDesign CS3"
tell document 1
repeat with thisFrame in text frames of layer "Laser"
display dialog (every text of thisFrame) as string
end repeat
end tell
end tell
Then my script fails when I try to do something like this:
set yellOff to 4
tell application "Adobe InDesign CS3"
tell document 1
repeat with thisFrame in text frames of layer "Laser"
tell text frame thisFrame
set {bTg, bLg, bBg, bRg} to geometric bounds
make rectangle with properties geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}item layer: "Default"}
end tell --thisFrame
end repeat
end tell --doc1
end tell --app
It finds the first text frame, but chokes on making the rectangle. I’ve played around with the properties, but it doesn’t want to make a rectangle.
“Adobe InDesign CS3 got an error: Cannot create an additional item. Operation not permitted on this object”
In the dictionary, I’m seeing that the rectangle is is contained by the same things that the document is. I’m not seeing what may be obvious, sam
it doesn’t work inside the loop because you are trying to tell the text frame to make the new rectangle you need to take it out of the tell text frame block. Then when you do the make new rectangle command you need to specify where you want to put it like this
****** example code not tested ***********
tell application "Adobe InDesign CS3"
tell document 1
repeat with thisFrame in text frames of layer "Laser"
tell text frame thisFrame
set {bTg, bLg, bBg, bRg} to geometric bounds
end tell
make rectangle at beginning of page 1 with properties geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}item layer: "Default"}
end repeat
end tell
end tell
Thanks for responding. Unfortunately, it dumps the entire document’s rectangles onto the current page. The issue is that when you enclose the thisFrame tell blocks into a page’s tell blocks, it fails. Remember, I have to iterate every on this layer on every page. Using “every” did not seem to help also.
set yellOff to 4
tell application "Adobe InDesign CS3"
tell document 1
repeat with thisPage from 1 to count of pages
tell page thisPage
repeat with thisFrame in text frames of layer "Laser" -->>fails here because it cannot count text frames in a layer, which was the question earlier
tell text frame thisFrame
set {bTg, bLg, bBg, bRg} to geometric bounds
end tell
make rectangle at beginning of page 1 with properties {geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}, item layer:"Default"}
end repeat --thisFrame
end tell --thisPage
end repeat --thisPage
end tell --doc1
end tell --app
Clearly, I’m not understanding ID’s hierarchy of certain page items, sam
set yellOff to 4
tell application "Adobe InDesign CS3"
tell document 1
repeat with i from 1 to count of pages
set textboxes to geometric bounds of every text frame of page i
repeat with aTextBox in textboxes
set {bTg, bLg, bBg, bRg} to aTextBox
make rectangle at beginning of page i with properties {geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}, item layer:"Default"}
end repeat --- done going through text boxes and making rectangles
end repeat -- done loopiing the pages
end tell --doc1
end tell --app
Reading through your code, I don’t see how it is distinguishing the text frames of just the “laser” layer. If you check my example, I’m iterating through each page and each text frame on one layer only. From what I can tell, it will get every text frame, no matter what layer it is on.
I still error out when I enclose my layer tell within a tell page block. If I’ve missed your point, pls point that out, thanx, sam
mmm sorry I dont’ have indesign on this computer to test these with
set yellOff to 4
tell application "Adobe InDesign CS3"
tell document 1
repeat with i from 1 to count of pages -- iterate through each page
--- make a list geometric bounds
set textboxes to geometric bounds of every text frame of layer "Laser" of page i -- if this one doesn't work try the next ones
-- set textboxes to geometric bounds of every text frame of page i of layer "Laser"
-- set textboxes to geometric bounds of every text frame of page i where layer is "Laser"
--- iterate through each item in the list we created
repeat with aTextBox in textboxes
set {bTg, bLg, bBg, bRg} to aTextBox
make rectangle at beginning of page i with properties {geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}, item layer:"Default"}
end repeat
end repeat -- done loopiing the pages
end tell --doc1
end tell --app
I’ll can take a look tonight on my other computer where I have a copy of indesign
mmm sorry I dont’ have indesign on this computer to test these with
set yellOff to 4
tell application "Adobe InDesign CS3"
tell document 1
repeat with i from 1 to count of pages -- iterate through each page
--- make a list geometric bounds
set textboxes to geometric bounds of every text frame of layer "Laser" of page i -- if this one doesn't work try the next ones
-- set textboxes to geometric bounds of every text frame of page i of layer "Laser"
-- set textboxes to geometric bounds of every text frame of page i where layer is "Laser"
--- iterate through each item in the list we created
repeat with aTextBox in textboxes
set {bTg, bLg, bBg, bRg} to aTextBox
make rectangle at beginning of page i with properties {geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}, item layer:"Default"}
end repeat
end repeat -- done loopiing the pages
end tell --doc1
end tell --app
I’ll can take a look tonight on my other computer where I have a copy of indesign
I hope this helps you
mm
Browser: Firefox 3.0b5
Operating System: Mac OS X (10.5)
Thank you. This should work. What I’m finding is that it’s failing to find the geometric bounds of every text frame of this layer. I’m sure it’s spelled right and valid. I’ve tried your other three iterations, but they yield the same error. Thanks for offering them.
“Adobe InDesign CS3 got an error: Can’t get geometric bounds of every text frame of layer "Laser" of page 1 of document 1.”
I look forward to your, or anyone else’s, response when you can make the time, thanx, sam
ahh this was allot easier with the dictionary at hand
tell application "Adobe InDesign CS3"
tell document 1
repeat with i from 1 to count pages
set geoBounds to geometric bounds of (every text frame of page i whose name of item layer is "Laser")
if geoBounds is not {} then
repeat with GB in geoBounds
set {bTg, bLg, bBg, bRg} to GB
make rectangle at beginning of page i with properties {geometric bounds:{bTg - yellOff, bLg - yellOff, bBg + yellOff, bRg + yellOff}, item layer:"Default"}
end repeat
end if
end repeat
end tell
end tell
Thank you very much for taking the time to get this working. It absolutely does work.
Here’s what I don’t get: I believe you and I are looking at the same dictionary but the difference between my approach and yours is that we’re pulling the same hierarchy but yours is within the document tell block, where mine was drilling down.
As someone converting my Quark scripts into ID3 scripts, I always got it working if I got the hierarchy right. But it failed here, even though text frames are contained by document, spreads, pages, layers.
My question is how would I know that I cannot drill down as I did, but a higher view as yours is? What did you see in the dictionary that I did not? thanx, sam
what I saw was that pages and layers are on the different branchs if you will so the tree is like this
document
pages layers
text frames text frames
so you can access text frames by layer or by page so then I had to figure out how to bridge the gap
so i looked at the properties of the text frame to see if I could reference one or the other and found “item layer” which is a properties of the text box that tells me what layer the text frame is on
also I don’t think you can tell a page to make an object rather you must tell the object where it you want it to be made
as far as the drill down… my technique is still a drill approach however I’m using a different bit
the problem you where having has to do with scope and I wish I could explain it better maybe someone else is listening and can explain better than I