4 Replies Latest reply on Jul 2, 2011 6:11 AM by Napo Monasterio

    Placing multiple images at once

    Napo Monasterio

      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?

        • 1. Re: Placing multiple images at once
          [Jongware] Most Valuable Participant

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

          • 2. Re: Placing multiple images at once
            Napo Monasterio Level 1

            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

            • 3. Re: Placing multiple images at once
              [Jongware] Most Valuable Participant

              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[i]);
              

               

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

              • 4. Re: Placing multiple images at once
                Napo Monasterio Level 1

                Hey, perfect, thanks so much! Yeah, I'm pretty new at JS scripting, so I appreciate all the guidance!

                 

                I don't have to put them on separate pages, but I do have to manipulate them (all the same, fortunately). If so, to do anything to them, I guess I would be doing something such as:

                 

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

                  tabletSlideshow.pages.item(0).items(slideshowImages[i])).geometricBounds = ["yadayada"];

                 

                 

                Or is items() the wrong approach to it?

                 

                Thanks again for all the help! Very thankful!

                 

                N