7 Replies Latest reply on Oct 13, 2011 3:02 PM by [Jongware]

    Special Contact Sheet Script

    ryanarend

      I am looking for someone to create a custom InDesign script.  I need the script to take placed images from an existing document and copy them to a new document at the same size and crop.  It needs to be in a contact sheet format along with the filename under each image.

       

      If you can do this, please contact with your rate or any question you may have.

        • 1. Re: Special Contact Sheet Script
          [Jongware] Most Valuable Participant

          Okay, I seem to have a pretty high rating over here so let me give it a shot. Disclaimer: gosh my head is stuffed courtesy of the Yearly Flu, so this might not work as you thought it would. (Proper Rectangle Packing, for instance, is so problematic it's a mathematical problem all of its own and I wouldn't dare to give it a shot even without the Sniffin' Cold.)

           

           

          original = app.activeDocument;
          newOne = app.documents.add(true);
            
          newOne.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
          newOne.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            
          // Change Me -- this is A2
          // It should be pretty large -- at least 10 mm around the largest image you got.
          pageWidth = 420;
          pageHeight = 297;
          
           newOne.documentPreferences.pageWidth = pageWidth;
          newOne.documentPreferences.pageHeight = pageHeight;
          newOne.documentPreferences.facingPages = false;
          
          all = original.allGraphics;
          xpos = 10;
          ypos = 10;
            
          highest = 0;
          pg = 0;
          
           for (i=0; i<all.length; i++)
          {
                    orgImg = all[i].parent;
                    name = all[i].itemLink.name;
                    high = orgImg.geometricBounds[2] - orgImg.geometricBounds[0];
                    wide = orgImg.geometricBounds[3] - orgImg.geometricBounds[1];
            
                    if ((xpos + 5 + wide > pageWidth - 10) ||
                              (ypos + high+10 > pageHeight - 10))
                    {
                              xpos = 10;
                              ypos += highest+10;
                              if (ypos + high+10 > pageHeight - 10)
                              {
                                        newOne.pages.add();
                                        pg++;
                                        ypos = 10;
                                        highest = high;
                              }
                    }
          
          
                    img = orgImg.duplicate(newOne.pages[pg]);
                    img.move ([xpos, ypos]);
                    textframe = newOne.pages[pg].textFrames.add({geometricBounds:[ypos+high, xpos, ypos+high+10, xpos+wide]});
                    textframe.contents = name;
                    xpos += 5+wide;
                    if (high > highest)
                              highest = high;
          }
          
          • 2. Re: Special Contact Sheet Script
            ryanarend Level 1

            So close……it copies, places and ads the filename.  One problem…..it places everything on top of each other.  Want it to look more like the pic below.Screen shot 2011-10-12 at 5.17.35 PM.png

            • 3. Re: Special Contact Sheet Script
              [Jongware] Most Valuable Participant

              ryanarend wrote:

               

              it places everything on top of each other.

               

              Well no it doesn't. I would have noticed that.

               

              Want it to look more like the pic below.

               

              The second line of images should indent? The bottom right image (hardly visible) should intrude on the ones already placed? That's Rectangle Packing, a notorious hard problem.

               

              Perhaps Marc Autret will come along, after all he solved it for his Wordalizer.

              • 4. Re: Special Contact Sheet Script
                ryanarend Level 1

                This is what I'm getting from you script…..

                Screen shot 2011-10-13 at 2.27.16 PM.png

                 

                 

                 

                would like it to look more like this….

                Screen shot 2011-10-13 at 2.29.08 PM.png

                • 5. Re: Special Contact Sheet Script
                  [Jongware] Most Valuable Participant

                  Oh okay that's not what it should've done ... Your second image is what I get on my tests.

                   

                  Care to provide some details? I'm wteseting on a Mac, CS4 -- perhaps that's the problem.

                   

                  Because I'm a Metric guy I change the ruler settings to millimeters [*]; can you change your rulers to something else (picas, inches) and confirm they are in millimeters after running the script?

                   

                  [*] And, belately, I realize it's not Friendly not to change them back but fortunately in this case I can use it to remotely debug the problem ...

                  • 6. Re: Special Contact Sheet Script
                    ryanarend Level 1

                    After running some test, the problem seemed to be the millimeter setting.  Once you convert the original document to millimeters, it works fine in both CS4 & CS5.  Certainly a usable script.

                     

                    But, one last complaint.  It don't use the space on the page too well.  It leaves a lot of white space.  If there is anyway to fix this it would be greatly appreciated.

                     

                    Thanks for all your help.

                    • 7. Re: Special Contact Sheet Script
                      [Jongware] Most Valuable Participant

                      It's as I said -- Rectangle Packing is a mathematician's nightmare. The way the script works is simple:

                       

                      1. Set a start x and y position (in this case 10 mm from the top left edge)

                      2. Grab the next image.

                      3. Does it fit horizontally on the current 'line'? (Current x position plus 5 mm spacing plus current image width)

                      4. Yes, then we're done with this image;

                      else

                      5. Go to the next 'line', which is the current y position plus the height of the tallest image so far (saved in 'highest') so it won't ever overlap with something above. Reset x position to the left margin.

                      6. Does it fit vertically on the current line? (Current y position plus 10 mm spacing plus current image height)

                      7. Yes, done; else

                      8. Add a new page and start all over again at #1

                       

                      It probably could be improved slightly by saving the bottom left and right coordinates of each image per 'line' and testing if an image on the 'next' line would fit right underneath the one above it -- I would have to think it over.