Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Resize frames to fit content?

Community Expert ,
Sep 22, 2008 Sep 22, 2008
I'm putting together a slide show for the jury to select entries to be exhibited in an exhibition at the local art museum next spring.

So far it looks as if I can make a template and use Data Merge to create the pages from which the slides will be made (as a PDF), but I'd like to add a keyline around all the images after they've been placed. I can add a stroke to the frame in the template, but I'm using the fit to frame proportionally and centering options in the merge, and of course there tends to be white space on two sides of every image which I don't want to leave.

I could go back after the merge and do the fitting by hand, but that sort of defeats the purpose of all the automation, and there are about 500 pages.

So does anyone already have a script to size all image frames in a document to fit the content, or would you be willing to throw one together for me? I'm afraid that in this case I really don't have a budget to pay for it -- nobody is paying me either.

Thanks,

Peter
TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 22, 2008 Sep 22, 2008
Is it as simple as:

app.documents[0].rectangles.everyItem().fit(FitOptions.frameToContent);

It might be if you only use rectangles for this purpose.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
A first try. Disclaimer: written in 2 minutes, without trying in InDesign!

var allImages = app.activeDocument.allGraphics;


for (var i = 0; i < allImages.length; i++)

{

myImages.fit (FitOptions.FRAME_TO_CONTENT);

}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
Ooo -- Dave beat me to it. Perhaps you can use allGraphics where he said "rectangles", and avoid the loop. (I'm still not used to "everyItem".)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 22, 2008 Sep 22, 2008
Ah, Jongware's solution is better. Allows you to have other rectangles (or even other shapes holding graphics). However, he has dropped in a small error to test your debugging skills.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
Hur, hur. Well spotted -- that's what you get with not actually running it. I'll tell it to'morrow if you didn't get it by then ;-)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
Actually, it is as simple as rectangles, and I don't think I want to spend time de-bugging on this. How about a hint? :)

Is it "for (var i = 0; i < allImages.length; i++)"? should that not be "for (var i = 0; i < allImages.length -1; i++)"? or am I too far removed form my code writing days?

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
It's not that. The pre-decrement thingy is when you're looping from end to start (in a JS array of 10 elements length, the items are numbered 0..9. So if you're counting backwards, the actual items are length-1 to 0).

A hint .. look at where "allImages" gets used .. Remember, this variable holds a pointer to the images array you want to fit.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
I note also that the tow of you seem to disagree on the exact name of the fitting options.

Does it matter that there are also some text frames on the page?

Peter.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
jongware is starting to get beyond me here. :)

I can usually read the code well enough to understand what a script is doing, but it's been like 12 or more years since I actually tried to write any Java, let alone javascript, and I'm getting old and forgetful.

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
I copied the name directly out of my little InDesign helper. There are a few spelling variants possible, but I usually stick to what's in there (a.k.a. the official ESTK help).

Text frames should not be affected, theoretically, as "allGraphics" is advertised to contain "all graphics contained by the Document". The text frames fall under allPageItems ("all page items contained by the Document").

Did you notice I suddenly used another name for "allImages" somewhere? (Can't get any clearer than that!)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
>Did you notice I suddenly used another name for "allImages" somewhere? (Can't get any clearer than that!)

Now that you mention it...

And just for fun I tried Dave's version and it worked splendidly in CS3.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 22, 2008 Sep 22, 2008
FWIW, I found jongware's error when I tried to run the script.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2008 Sep 22, 2008
LATEST
OK, now that I know what the problem was, I used jongware's version , and it also works splendidly.

Thank you both very much. I owe you both a beer or something. :)

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines