Skip to main content
Participating Frequently
July 1, 2011
Answered

Placing multiple images at once

  • July 1, 2011
  • 1 reply
  • 1030 views

I've been trying to programmatically import multiple images into InDesign, but I'm having a small issue. From what I understand, a multiple selection returns an array, but the script is acting up on me. Here's what I've got so far:

var slideshowImages = File.openDialog("Choose the images you want incuded", "Files:*.jpg", true);

if((slideshowImages != "")&&(slideshowImages != null)){

var slideshowItems = tabletSlideshow.pages.item(0).place(slideshowImages);   <==== This is where I get the "Invalid value for parameter 'fileName' of method 'place' ....... " error.

slideshowItems = slideshowItems[0];

I can place one, but not multiple. Any ideas?

This topic has been closed for replies.
Correct answer Jongware

The usual way. Use slideshowImages.length to get the number of images; then, you can loop over all images and place each one of them:

for (i=0; i<slideshowImages.length; i++)

  tabletSlideshow.pages.item(0).place(slideshowImages);

-- although you need to think of a way to place each of the images on a page of their own, 'cause this loop will place them on top of each other on the first page.

1 reply

Jongware
Community Expert
Community Expert
July 1, 2011

It's easier than you think. The function File.openDialog already returns an array of file names! So this is why your failing line fails; you are handing it the entire array of file names instead of just one. You are doing the opposite; you attempt to place the entire array and treat the return value of "place" as the array.

Use this to place the first image:

var slideshowItem_first = tabletSlideshow.pages.item(0).place(slideshowImages[0]);

Participating Frequently
July 1, 2011

Hey Jongware, thanks for the prompt reply!

OK, this works now... I'm about to place an image, no problem. The issue is... I'm only about to place one.

I added

var slideshowItem_second = tabletSlideshow.pages.item(0).place(slideshowImages[1]);

to place the second item in the array... but what if I want to enter 3, or 12, or 27? It might change from time to time. So, how to do I tell it to place all of them?

Thanks!

N

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
July 2, 2011

The usual way. Use slideshowImages.length to get the number of images; then, you can loop over all images and place each one of them:

for (i=0; i<slideshowImages.length; i++)

  tabletSlideshow.pages.item(0).place(slideshowImages);

-- although you need to think of a way to place each of the images on a page of their own, 'cause this loop will place them on top of each other on the first page.