12 Replies Latest reply on Dec 20, 2012 2:08 AM by Laubender

    How I can generate a report of pictures coordinates?

    Patrick Gaudreault

      Hi,

       

      I need to extract the top left corner and bottom right corner coordinates of pictures in a document, with page number and images name.

      I understand the way geometricbounds works, but I'm unable to understand how the images are bound with the coordinate.

       

      Can Anyone help me!

       

      Thanks

        • 1. Re: How I can generate a report of pictures coordinates?
          -hans- Level 4

          Hi,

           

          I guess you mean the coordinates of the masked images = coordinates of a page item¿

           

          app.activeDocument.allGraphics will return a array of all graphics.

          check if parent of the graphic is a page item and get the geometric- or visual bounds. returned Bounds: [y1,x1,y2,x2]. so get the pairs for topleft and bottomright.

           

          The graphic itsself has got the properties parentPage and name.

          So you've got all you want.

           

          Hans-Gerd Claßen

          • 2. Re: How I can generate a report of pictures coordinates?
            -hans- Level 4

            You may try this snippet:

             

             

            #target Indesign
            
            //check for active Document
            if(app.documents.length != 0){
               var currDoc = app.activeDocument;
               //array to catch infos
                var  graphicsInfos = [];
                  }else{
                      //no open document
                   exit();}
            
            //necessary
            currDoc.zeroPoint = [0,0];
            
            //get Measurement Units as string, set ruler Origin to Page
            with(currDoc.viewPreferences){
                var hUnit = horizontalMeasurementUnits.toString();
                var vUnit = verticalMeasurementUnits.toString();
                rulerOrigin    =  RulerOrigin.PAGE_ORIGIN;
                    }
                
                //get all graphics of document
            var getGraphics = currDoc.allGraphics;
            
            for(var i = 0; i < getGraphics.length; i++){
                //create object to store graphic infos
                currInfo = new Object();
            currGraphic = getGraphics[i];
            
            //Position, on page
            currInfo['Position'] = 'NaN'
            if(currGraphic.parent.hasOwnProperty('visibleBounds')){
                currParentBounds = currGraphic.parent.visibleBounds;
                topLeft = '' + currParentBounds[1] + ' ' + hUnit + ' / ' + currParentBounds[0] + ' ' + vUnit;
                bottomRight =  '' + currParentBounds[3] + ' ' + hUnit + ' / ' + currParentBounds[2] + ' ' + vUnit;
                currInfo['Position'] = 'Position\n topLeft: ' + topLeft + ' | ' + 'bottomRight: ' + bottomRight; 
                }
                
                currInfo['Page'] = 'Page: ' + currGraphic.parentPage.name;
                currInfo['Name'] = 'Name: ' + currGraphic.itemLink.name;
                //store infos of graphic in array
            graphicsInfos.push(currInfo) ;
            }
            
            //arrayToString
            l = graphicsInfos.length;
            newString = currDoc.name + '\n';
            while(l--){
                newString = newString + graphicsInfos[l].Name + '\n' + graphicsInfos[l].Page + '\n' + graphicsInfos[l].Position + '\n\n'
                }
            
            //write file
                var _file = new File('~/Desktop/' + currDoc.name.replace(/indd/, '') + 'txt');
                    _file.open( 'w' ); 
                    _file.encoding = 'UTF-8'; 
                _file.write( newString ); 
                _file.close();
            

            Report will be saved on the desktop. Indesign-Documentname + txt

             

            Hope it'll run

             

            Hans-Gerd Claßen

            • 3. Re: How I can generate a report of pictures coordinates?
              Patrick Gaudreault Level 1

              Hi Hans, it didn't work, but I came up with this script, but I need to add page number

               

              Here's the script I came up:

               

              app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

              list = [];

              imgs = app.activeDocument.allGraphics;

              unitname = getCurrentUnit();

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

              {

              left = imgs[i].parent.geometricBounds[1];

              top = imgs[i].parent.geometricBounds[0];

              bottom = imgs[i].parent.geometricBounds[3];

              right = imgs[i].parent.geometricBounds[2];

              // some fair rounding

              switch (unitname)

              {

                case 'px':

                 left = roundMe(left, 1);

                 top = roundMe(top, 1);

                 bottom = roundMe(bottom, 1);

                 right = roundMe(right, 1);

                

                 break;

                case 'in':

                 left = roundMe(left, 2);

                 top = roundMe(top, 2);

                 bottom = roundMe(bottom, 2);

                 right = roundMe(right, 2);

               

                 break;

                default:

                 left = roundMe(left, 1);

                 top = roundMe(top, 1);

                 bottom = roundMe(bottom, 1);

                 right = roundMe(right, 1);

              }

              list.push (imgs[i].itemLink.name+'\t'+'('+left+','+top+')'+'\t('+bottom+','+right+')' );

              }

              // alert (list.join('\r')); exit();

              defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");

              if (File.fs == "Windows")

              writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );

              else

              writeFile = defaultFile.saveDlg( 'Save report');

              if (writeFile != null)

              {

              if (writeFile.open("w"))

              {

                writeFile.encoding = "utf8";

                writeFile.write (list.join("\r")+"\r");

                writeFile.close();

              }

              }

              function roundMe(val,to)

              {

              var t = 1;

              while (to-- > 0) t *= 10;

              return Math.round(val*t)/t;

              }

              function getCurrentUnit ()

              {

              switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)

              {

                case MeasurementUnits.POINTS: return "pt";

                case MeasurementUnits.PICAS: return "pt";

                case MeasurementUnits.INCHES: return "in";

                case MeasurementUnits.INCHES_DECIMAL: return "in";

                case MeasurementUnits.MILLIMETERS: return "mm";

                case MeasurementUnits.CENTIMETERS: return "cm";

                case MeasurementUnits.CICEROS: return "c";

                case MeasurementUnits.AGATES: return "ag";

                case MeasurementUnits.PIXELS: return "px";

                default: alert ("Oh, come on!"); exit(0);

              }

              }

               

              It's working, but I need the page number and I don't know how to insert the page number.

               

              Have any idea?

               

              Thanks for your help!

               

              Patrick

              • 4. Re: How I can generate a report of pictures coordinates?
                Sajeev Sridharan Level 4

                Try this:

                 

                app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

                list = [];

                currInfo = new Object();

                imgs = app.activeDocument.allGraphics;

                unitname = getCurrentUnit();

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

                {

                left = imgs[i].parent.geometricBounds[1];

                top = imgs[i].parent.geometricBounds[0];

                bottom = imgs[i].parent.geometricBounds[3];

                right = imgs[i].parent.geometricBounds[2];

                currInfo = 'Page: ' + imgs[i].parentPage.name;

                 

                 

                // some fair rounding

                switch (unitname)

                {

                  case 'px':

                   left = roundMe(left, 1);

                   top = roundMe(top, 1);

                   bottom = roundMe(bottom, 1);

                   right = roundMe(right, 1);

                 

                   break;

                  case 'in':

                   left = roundMe(left, 2);

                   top = roundMe(top, 2);

                   bottom = roundMe(bottom, 2);

                   right = roundMe(right, 2);

                 

                   break;

                  default:

                   left = roundMe(left, 1);

                   top = roundMe(top, 1);

                   bottom = roundMe(bottom, 1);

                   right = roundMe(right, 1);

                }

                 

                 

                 

                 

                list.push (imgs[i].itemLink.name+'\t'+'('+left+','+top+')'+'\t('+bottom+','+right+')' + '\t' + currInfo);

                }

                // alert (list.join('\r')); exit();

                defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");

                if (File.fs == "Windows")

                writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );

                else

                writeFile = defaultFile.saveDlg( 'Save report');

                if (writeFile != null)

                {

                if (writeFile.open("w"))

                {

                  writeFile.encoding = "utf8";

                  writeFile.write (list.join("\r")+"\r");

                  writeFile.close();

                }

                }

                function roundMe(val,to)

                {

                var t = 1;

                while (to-- > 0) t *= 10;

                return Math.round(val*t)/t;

                }

                function getCurrentUnit ()

                {

                switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)

                {

                  case MeasurementUnits.POINTS: return "pt";

                  case MeasurementUnits.PICAS: return "pt";

                  case MeasurementUnits.INCHES: return "in";

                  case MeasurementUnits.INCHES_DECIMAL: return "in";

                  case MeasurementUnits.MILLIMETERS: return "mm";

                  case MeasurementUnits.CENTIMETERS: return "cm";

                  case MeasurementUnits.CICEROS: return "c";

                  case MeasurementUnits.AGATES: return "ag";

                  case MeasurementUnits.PIXELS: return "px";

                  default: alert ("Oh, come on!"); exit(0);

                }

                }

                 

                 

                 

                Vandy

                • 5. Re: How I can generate a report of pictures coordinates?
                  -hans- Level 4

                  Hi,

                   

                  it's tested for ID CS 5.5 Mac & PC -> Runs fine here.

                  (Won't run CS4 & prior)

                   

                  Have a nice day

                   

                  Hans-Gerd Claßen

                  • 6. Re: How I can generate a report of pictures coordinates?
                    Patrick Gaudreault Level 1

                    Thanks everyone for your help!

                     

                    The script works, but I don't know why, I have an Error Number 21

                     

                    Capture d’écran 2012-12-18 à 22.46.07.png

                    The script works with some files, but not with other. I don't understand why!

                     

                    Also, I need to get the pictures from a specified layer.

                     

                    Anyone have a suggestion?

                     

                    I've worked with the script from Vandy.

                     

                    Thanks for your help!

                     

                    Patrick

                    • 7. Re: How I can generate a report of pictures coordinates?
                      Laubender Adobe Community Professional & MVP

                      @Patrick – if "parentPage" returns "null", it means, that the object (the image, better: the  container that hold the image) resides on the pasteboard.

                       

                      And therefore there could be no "parentPage".

                       

                      Uwe

                      • 8. Re: How I can generate a report of pictures coordinates?
                        Patrick Gaudreault Level 1

                        Hi,

                         

                        Thanks for the tips, an image was left outside the pasteboard!

                         

                        The only thing left is to select only the pictures on a layer.

                         

                        Have any idea about the script, I didn't find anything.

                         

                        Thank you for your help!

                         

                        Patrick

                        • 9. Re: How I can generate a report of pictures coordinates?
                          -hans- Level 4

                          Hi,

                           

                          a layer has got its own property 'allGraphics'.

                          Layers parent is the document. Any idea¿ Have a try!

                           

                          Hans-Gerd Claßen

                          • 10. Re: How I can generate a report of pictures coordinates?
                            Laubender Adobe Community Professional & MVP

                            @Hans-Gerd – but that method has one drawback:

                             

                            the scope of "allGraphics" of a "layer" Object is restricted to "normal" document pages.
                            Graphics on master pages are left out there. You have to deal with them differently…

                             

                            Some call it a bug, some call it "it's by design" ;-)

                             

                            Uwe

                            • 12. Re: How I can generate a report of pictures coordinates?
                              Laubender Adobe Community Professional & MVP

                              I should have said:

                               

                              "is restricted to "normal" document spreads", not "pages".


                              All graphics of containers on the pasteboards are included as well.

                               

                              Uwe