Copy link to clipboard
Copied
Hi all,
I’m just starting out with AppleScript, I wonder if I could trouble somebody for some advice?
The repeat loop below looks through any graphic frames on my InDesign page, gets the bounds of each frame and then changes the size of them by a set amount given by the user. (theChosenBleed)
All good so far apart from the ‘set FrameHeights’ and ‘set FrameWidths’ variables, this is saving the width/height of the first frame it finds in the loop, rather than making a list of the dimensions of every one it finds.
If there are three frames on the page, sized at 300x400mm each for example, I am getting this
FrameWidths = 300
FrameHeights = 400
What I actually need is below;
FrameWidths = 300, 300, 300
FrameHeights = 400, 400, 400
Does anybody know what I’m doing wrong?
The script is below;
repeat with oneFrame in (get all page items of layerImages)
set {a, b, c, d} to geometric bounds of oneFrame
set FrameWidths to {d-b}
set FrameHeights to {c-a}
set geometric bounds of oneFrame to {a + theChosenBleed, b + theChosenBleed, c - theChosenBleed, d - theChosenBleed}
make rectangle with properties {geometric bounds:{a + theChosenBleed, b + theChosenBleed, c - theChosenBleed, d - theChosenBleed}, stroke color:"Cut", stroke weight:2}
end repeat
Copy link to clipboard
Copied
Your script is OK if what you want is the geometric bounds of the rectangles to be reduced per the value of theChosenBleed. Not too sure what you want with the frameWidths and frameHeights. If what you are wanting is to check the widths and heights of each item, you then have a problem. (1) Don't use curly braces for computation (2) Collect your values in a list, otherwise at the end of the script the value of FrameWidths and FrameHeights will be for only the last iteration of the loop (the last item of the list).
To verify values for height and width, establish a list variable outside of the repeat loop and add the value of the variables to the respective list as part of the repeat loop.
--outside of the loop
set fWList to {}
set fHList to {}
--inside the loop
set frameWidths to (d - b) --notice use parens not curly braces
set end of fWList to frameWidths
set frameHeights to (c - a) --notice use parens not curly braces
set end of fHList to frameHeights
--at the end of the script, verify values
{fWList, fHList}
Copy link to clipboard
Copied
Thanks so much thats brilliant!
Sorry to add another question, but is there a way to add together the numbers contained in each list?
ie. if fwList is 300, 300, 300 i'd love it to save 900 to a variable called totalWidths
To give a bit of context I am trying to work out the square meterage of the images placed in my document, so I need to add together all the heights and also the sum of all the widths at the end of the script so I can calculate from there.
Thanks so much again
Find more inspiration, events, and resources on the new Adobe Community
Explore Now