7 Replies Latest reply on Jan 30, 2009 10:36 AM by MarkPeterson01

    Place Images

    MarkPeterson01
      (CS3) I'm attempting to modify the ImageCatalog script. The purpose of following script is to place the four images contained in the "image2" folder in four text frames (one text frame per page) in a four-page document. Nothing happens when the script runs.

      //Import image files
      var myFolder = File("c:\\junk\\junk2\\image2");
      var myDocument = app.activeDocument;
      var myFiles = new Array;
      myFiles = myFolder.getFiles("*");

      for (var myFileCounter = 0; myFileCounter < myFiles.length;
      myFileCounter++){
      myFiles.push([myFileCounter]);
      }

      //Place image files
      //Number of frames

      var myNumberOfFrames = "4";

      for (var myCounter = 0; myCounter < myNumberOfFrames; myCounter++){
      var myFile = myFiles[myCounter];
      var myRectangle = myDocument.rectangles.item(myCounter);
      myRectangle.place(File(myFile));
      }

      What am I doing wrong?
        • 1. Re: Place Images
          Loic.Aigon Adobe Community Professional
          As far as I know, you are speaking japanese to an italian ;-)
          Your instructions look unappropriate:
          mYfolder may point to a folder object, not a file.
          myFolder = Folder("/c/junk/junk2/image2/");

          myFiles = myFolder.getFiles("*");
          This will return a array of files by defaut, no need to reconstruct one.
          myFileCounter is indeep myFiles.length;

          var myRectangle = myDocument.rectangles.item(myCounter)
          means they already exist or you have yo add them with coordinates.

          But I am not the specialist here ;-)
          Hope it helps
          Loic
          • 2. Re: Place Images
            MarkPeterson01 Level 1
            Hi Loic,
            Thank you for the quick response. You may have caught one error: the four pages contain text frames, not rectangles. Despite the change, nothing happens when the script runs.

            Thanks,
            Mark
            • 3. Re: Place Images
              Loic.Aigon Adobe Community Professional
              Hi Mark,

              Here with CS3, it runs well :
              //Given 4 rectangles placed on a page of a Indesign document.

              //Import image files
              var myFolder = Folder("/Users/KimLien/Documents/Loïc/Tests");
              var myDocument = app.activeDocument;
              myFiles = myFolder.getFiles();
              for (var myCounter = 0; myCounter < 4; myCounter++)
              {
              var myFile = myFiles[myCounter];
              var myRectangle = myDocument.rectangles.item(myCounter);
              myRectangle.place(File(myFile));
              }
              • 4. Re: Place Images
                MarkPeterson01 Level 1
                Loic,

                Thank you for the code. When the following line executes, I get the error shown below:

                myRectangle.place(File(myFile));

                Error:
                The file C:\Users\mp\documents\tmp000001 was not found.

                I'm using the "c:\\junk\\junk2\\image2" path.

                Mark
                • 5. Re: Place Images
                  Loic.Aigon Adobe Community Professional
                  Hi Mark,
                  When I am confused with writing system path, I use this technique to check them out (waiting to get more confidence on dealing with them ;-))

                  var myFolder = Folder.selectDialog();
                  $.writeln(myFolder.fullName);

                  By the way, did you have a look on the scripting documentation, it has a big part on dealing with files and folders objects ?
                  • 6. Re: Place Images
                    MarkPeterson01 Level 1
                    Hi Loic,

                    I was looking at the core JavaScript classes in the CS4 object browser last night. I'll read the section on file and folder objects today.

                    Thanks,
                    Mark
                    • 7. Re: Place Images
                      MarkPeterson01 Level 1
                      Hi Loic,

                      The script is fine. The error I received was caused by a problem with one of the files I was trying to import.

                      Thanks,
                      Mark