I hope someone will be able to help me. What I am trying to do is select a text box by its bounds. I believe that this should be possible but so far I have had no luck.
What I have is multiple page documents where each page contains multiple text boxes. One of the text boxes (which should have the same bounds) contains the job number. I want to run a script to make sure that number is the same in all the boxes without me having to manually go check.
I am able to get the bounds by looping through the pages and then each individual text box but I am having trouble comparing the results with the bounds I am looking for. Here is a sample code
set bnds to {"10.0"", "-0.1"", "11.0"", "0.1""}
tell Quark tell document 1
repeat with i from 1 to (count of pages)
tell page i repeat with i from 1 to (count of text boxes)
tell box i
if bounds = bnds then
display dialog "found it!"
end tell
end repeat
end tell
end repeat
end tell
end tell
If anyone would offer help or advice I would appreciate it greatly.
Thanks and have a great day
T.J.,
I orginally tried something similar to your suggestion,
because I did not want to loop through every text box in the document. I just wanted a list of the ones with the particular bounds. However, when I try this I get the error message:
I am not sure why. So I thought that if I went to each text box individually then I would be able to compare the bounds. I was not able to accomplish that either. I get a similar error message as the one above.
Thanks for your input and if you have any additional suggestions please let me know.
Joe
tet,
Thank you very much for your suggestion. It worked great and I think I may use it. The only problem I have now is that because I have the script look at every text box (700+) it takes quite a bit of time. I have to come up with a way to make it faster.
In case you are interested here is what I have come up with so far:
set jbName to "jobNumber" set bnds1 to {"10.858"", "-0.146"", "11.01"", "0.865""} set bnds2 to {"0.146"", "9.569"", "0.32"", "10.551""}
tell document 1 of application "QuarkXPress™"
activate
set njNum to text returned of (display dialog "Enter new number:" default answer "") repeat with i from 1 to (count of pages)
tell page i
repeat with j from 1 to (count of text boxes)
tell text box j
set {y1, x1, y2, x2} to (bounds) as list
if (y1 as string) = (item 1 of bnds1) and ¬
(x1 as string) = (item 2 of bnds1) and ¬
(y2 as string) = (item 3 of bnds1) and ¬
(x2 as string) = (item 4 of bnds1) or ¬
(y1 as string) = (item 1 of bnds2) and ¬
(x1 as string) = (item 2 of bnds2) and ¬
(y2 as string) = (item 3 of bnds2) and ¬
(x2 as string) = (item 4 of bnds2) then
set story 1 to njNum
set name to jbName
exit repeat
end if
end tell
end repeat
end tell end repeat end tell
tell document 1 of application "QuarkXPress™ 4.11"
set jbName to "jobNumber"
set bnds1 to {"10.858"", "-0.146"", "11.01"", "0.865""} as inches rectangle
set bnds2 to {"0.146"", "9.569"", "0.32"", "10.551""} as inches rectangle
activate
set njNum to text returned of (display dialog "Enter new number:" default answer "")
repeat with i from 1 to (count of pages)
tell page i
repeat with j from 1 to (count of text boxes)
tell text box j
set boxBounds to (bounds as inches rectangle)
if ((boxBounds = bnds1) or (boxBounds = bnds2)) then
set story 1 to njNum
set name to jbName
exit repeat
end if
end tell
end repeat
end tell
end repeat
end tell
At the density of boxes you’re talking about, this is about 20% faster.
You can also coerce bnds1 & 2 to measurements rectangles and compare it directly to the bounds, but for some reason that runs slightly slower on my machine than the above.
tet,
I had tried to set the bounds as measurements rectangle and it would not find any matches and I just tried setting the bounds as inches rectangle and it does not find any matches either. The only way so far that I have been able to get matches is from your previous suggestion of comparing the measurements one at a time.
To help on the speed issue I am going to name the boxes during the first run so any consecutive runs will use the name and hopefully be faster.
Here is what I have so far:
property jbName : "jobNumber" property bnds1 : {"10.858"", "-0.146"", "11.01"", "0.865""} property bnds2 : {"0.146"", "9.569"", "0.32"", "10.551""}
tell application "QuarkXPress™"
activate
if (exists of document 1) is false then
display dialog "Please open a Quark document." buttons ¬
"OK" default button 1 with icon 0
error number -128 end if
set njNum to text returned of (display dialog "Enter new number:" default answer "") tell document 1
repeat with i from 1 to (count of pages)
tell page i
if exists (text box jbName) then
set story 1 of text box jbName to njNum
else
repeat with j from 1 to (count of text boxes)
tell text box j
set {y1, x1, y2, x2} to (bounds) as list
if (y1 as string) = (item 1 of bnds1) and ¬
(x1 as string) = (item 2 of bnds1) and ¬
(y2 as string) = (item 3 of bnds1) and ¬
(x2 as string) = (item 4 of bnds1) or ¬
(y1 as string) = (item 1 of bnds2) and ¬
(x1 as string) = (item 2 of bnds2) and ¬
(y2 as string) = (item 3 of bnds2) and ¬
(x2 as string) = (item 4 of bnds2) then
set story 1 to njNum
set name to jbName
exit repeat
end if
end tell
end repeat
end if
end tell
end repeat end tell end tell
I would appreciate any additional comments or suggestions you might have.
Thanks for your time and help.
Joe
There is definately some wierdness going on. I think it may be due to the fact that the bounds are not nice round numbers but I am not sure.
And yes I have tried points with the same type of results as when using inches or meausrement rectangles. I was not able to get any matches.
Thanks for your time and help.
Joe