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

Resize frames to fit content?

Community Expert ,
Sep 22, 2008 Sep 22, 2008

Copy link to clipboard

Copied

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

Views

2.4K

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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".)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 ;-)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

>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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

FWIW, I found jongware's error when I tried to run the script.

Dave

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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