2 Replies Latest reply on Jul 4, 2017 11:31 PM by hamdifem

    move to margin corners

    hamdifem Level 1

      Hi. There is an snippet idms in a folder. I want to move these to the corner of margin. On the order of up left, down left, up right and down right. And it should open new page after every four. It should be maximum 4 on every page. How should I build a loop

      I tried but i failed

       

      unsuccessful

       

      var myFolder = File("D:\\PNG");
      var folderIn = myFolder.getFiles("*.idms");
      var corner = [
      app.activeDocument.marginPreferences.top,
      app.activeDocument.marginPreferences.left,
      app.activeDocument.marginPreferences.bottom,
      app.activeDocument.marginPreferences.right
      ]
      var arr=[0,0];  
      for(i = 0; i < folderIn.length; ++i) {
      var inSnp = app.activeDocument.pages[0].place(folderIn[i], arr)[0];
      inSnp.move([corner[i], inSnp.geometricBounds[0]]);  
      }
      
        • 1. Re: move to margin corners
          Jump_Over Level 5

          Hi,

           

          I can see a workaround like this:

          1. prepare measurments and zeroPoint in your Doc

              to calculate corner's we need to use page.bounds (+/- particular margin)

              and page.bounds are returned in POINTS

          2. make sure a doc IS NOT facing pages

              to simplify move(to:[x,y]) procedure

          3. get IDMS into array

              alike you did it

          4. iterate through this array, count steps

              shift elements - so array length decreases

          5. set last page as a target and place current snippet to this page (some default location, no matter where)

          6. check current step value and switch corner calculation using 'case: step'

              assumings: originally snippet's absoluteRotationAngle = 0

              according to above we need to calculate [x,y] values as a target for moving  snippet's LeftUp corner.

          7. if step%4 == 3 check folderIn length

              if NOT END -- add a new page and update cPage and margins vars

          8. move current snippet to a proper point

          9. next step

           

          code to check:

          var  mDoc = app.activeDocument;
          mDoc.documentPreferences.facingPages = false;
          app.transformPreferences.transformationsAreTotals = true;
          with (mDoc.viewPreferences) {
              horizontalMeasurementUnits = MeasurementUnits.POINTS;
              verticalMeasurementUnits = MeasurementUnits.POINTS;
              rulerOrigin = RulerOrigin.PAGE_ORIGIN;
              }
          mDoc.zeroPoint = [0,0];
          //|||||||||||||||||||||||||||||||||||||||||||||||
          var
              myFolder = File("D:\\PNG"), 
              folderIn = myFolder.getFiles("*.idms"),
              cFile,
              cPage = mDoc.pages[-1],
              margins = detectMargins(cPage),
              step = -1, inSnp, cCorner,
              mSize = {
                  w: 0,
                  h: 0
                  }; 
          while ( cFile = folderIn.shift() ) { 
              step++;
              inSnp = cPage.place(cFile)[0];
              mSize.w = inSnp.geometricBounds[3] -  inSnp.geometricBounds[1];
              mSize.h = inSnp.geometricBounds[2] -  inSnp.geometricBounds[0];
              switch (step%4) {
                  case 0:
                      cCorner = [
                          margins.left,
                          margins.top,
                          ];
                      break;
                  case 1:
                      cCorner = [
                          margins.left,
                          margins.bottom - mSize.h,
                          ];
                      break;
                  case 2:
                      cCorner = [
                          margins.right - mSize.w,
                          margins.top
                          ];
                      break;
                  case 3:
                      cCorner = [
                          margins.right - mSize.w,
                          margins.bottom - mSize.h,
                          ];
                      if (!folderIn.length) break;
                      cPage = mDoc.pages.add(LocationOptions.AT_END);
                      margins = detectMargins(cPage);
                  }
              inSnp.move(cCorner);   
              } 
          function detectMargins(mPage) {
              return new Object ({ 
                  top: mPage.marginPreferences.top, 
                  left: mPage.marginPreferences.left, 
                  bottom: mPage.bounds[2] - mPage.marginPreferences.bottom, 
                  right: mPage.bounds[3] - mPage.marginPreferences.right 
                  });
              }
          

           

          Jarek

          • 2. Re: move to margin corners
            hamdifem Level 1

            It was really wunderfull and new ideas came to mind

            Thank you very much