3 Replies Latest reply on Jun 21, 2016 8:00 AM by selvam214

    Image arrangement - more white space

    selvam214 Level 1

      Hi All,

      We have more images in a document. While using the below code, lots of white space available in output. Can you please check attached document (current) and how to fill the pages with effectively. The manual arrangement document also available with this discussion (target).

       

       

      Additionally, guide to how will use the algorithm calculation based on this request.

       

       

       

       

       

       

       

      //Target Doucment

      var myTargetDocument = app.activeDocument;

      //Target Document Measurement in Points

      myTargetDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

      myTargetDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

      myTargetDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

      var myImages = myTargetDocument.allGraphics;

       

      //Target Document Page Width and Height

      var myPageWidth = app.activeDocument.documentPreferences.pageWidth;

      var myPageHeight = app.activeDocument.documentPreferences.pageHeight;

       

      //--Place images in the new Target Document

      pg = 0;

      myX2 = 0;

      myYY1 = 0;

      myY1 = 18;

      var tempRotationAngle;

      var tempabsoluteVerticalScale

            

      for (i = 0; i < myImages.length; i++) {

          app.activeWindow.transformReferencePoint = AnchorPoint.TOP_LEFT_ANCHOR;

              myX1 = myX2 + 18;

          var myH = myImages[i].parent.geometricBounds[2] - myImages[i].parent.geometricBounds[0];

          var myW = myImages[i].parent.geometricBounds[3] - myImages[i].parent.geometricBounds[1];

              tempRotationAngle=myImages[i].parent.rotationAngle;

              tempabsoluteVerticalScale=myImages[i].parent.absoluteVerticalScale;

         //condition 1

         if((myImages[i].parent.rotationAngle > 0 && myImages[i].parent.rotationAngle <= 180) || (myImages[i].parent.absoluteVerticalScale>=-100 && myImages[i].parent.absoluteVerticalScale<-1))

         {

             myImages[i].parent.rotationAngle=0;

              myImages[i].parent.absoluteVerticalScale=100;

          } 

       

          if (myW > myPageWidth) {

              alert(myImages[i].itemLink.name + " width is greater than target document page width. Please fix it and rerun the tool");

              exit(0);

          }

       

          if (myH > myPageHeight) {

              alert(myImages[i].itemLink.name + " height is greater than target document page height. Please fix it and rerun the tool");

              exit(0);

          }

       

          myY2 = myY1 + myH;

          myX2 = myX1 + myW;

        

                  if (myX2 > myPageWidth) {

                  myX2 = 0;

                  myX1 = myX2 + 18;

                  myX2 = myX1 + myW;

                  myY1 = myYY1 + 48;

                  myY2 = myY1 + myH;

          }

       

         if(((myImages[i].parent.rotationAngle > 0 && myImages[i].parent.rotationAngle <= 180) || (myImages[i].parent.absoluteVerticalScale>=-100 && myImages[i].parent.absoluteVerticalScale<-1)) && myX1==36)

         {

             myX1=myX1+(myW*2);

          }     

       

              if (myY2 > myPageHeight) {

                  myTargetDocument.pages.add(LocationOptions.atEnd);

                  pg++;

                  myY2 = 0;

                  myY1 = myY2 + 36;

       

                  myY2 = myY1 + myH;

                  myX2 = 0;

                  myX1 = myX2 + 18;

                  myX2 = myX1 + myW;

                  myYY1 = 0;

              }

          myImages[i].parent.move(myTargetDocument.pages[pg]);

          myImages[i].parent.move([myX1,myY1]);

          myX2 = myImages[i].parent.geometricBounds[3];

          myYY2 = myImages[i].parent.geometricBounds[2];

          if (myYY2 > myYY1) {

                      myYY1 = myYY2;

          }

          pageNo1=myImages[i].parent.parentPage.name;

            myImages[i].parent.rotationAngle=tempRotationAngle;

                    myImages[i].parent.absoluteVerticalScale=tempabsoluteVerticalScale;

      pageNo2=myImages[i].parent.parentPage.name;

       

      if (parseInt(pageNo1)==parseInt(pageNo2))

      {

         if((myImages[i].parent.rotationAngle > 90 && myImages[i].parent.rotationAngle <= 179) || (myImages[i].parent.absoluteVerticalScale>=-100 && myImages[i].parent.absoluteVerticalScale<-1))

         {

                myImages[i].parent.move([myX1+myW+6,myY1]);

                 myX1=myX1+myW+6;

           }

      }

       

      if (parseInt(pageNo1)!=parseInt(pageNo2))

      {

         if(myImages[i].parent.rotationAngle == 180 && myImages[i].parent.absoluteVerticalScale==-100)

         {

                  myTargetDocument.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;

                myImages[i].parent.move([myX1+myW+6+myPageWidth,myY1]);

                 myX1=myX1+myW+6+myPageWidth;

                   myTargetDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

           }

      }

       

      if(myImages[i].parent.rotationAngle == 0 && myImages[i].parent.absoluteVerticalScale == -100)

         {

                myImages[i].parent.move([myX1,myY1+myH]);

                 myY1=myY1+myH+12;

           }

       

      }

       

      //To remove blank pages

      for (k = myTargetDocument.pages.length - 1; k > 0; k--) {

          if (myTargetDocument.pages[k].rectangles.length == 0) {

              myTargetDocument.pages[k].remove();

          } else {

              break;

          }

      }

       

       

      Target sample (after manual arrangement):

      Dropbox - Join Dropbox to view this file

       

      Current tool and source file:

      Dropbox - Join Dropbox to view this file

       

       

       

       

       

      -------------

      Thanks,

      dev