7 Replies Latest reply on Nov 3, 2014 7:22 AM by hamdifem

    why this command does not work properly

    hamdifem Level 1

      I want to move the page breaks in some of the text frame

      as the picture

      however facing pages located does not carry some text frames

      İmage25.jpg

       

      var myDoc = app.activeDocument;
      
      
      myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;    
      myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;    
      myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
      myDoc.zeroPoint = [0,0];
      
      
      
      
      
      
      function cmyk(t, c, m, y, k) {
          return function() {
              var myColor;
      
      
              myColor = app.activeDocument.colors.item(t);
              if(!myColor || !myColor.isValid) {
                  myColor = app.activeDocument.colors.add();
                  myColor.properties = {name:t, model: ColorModel.PROCESS, space: ColorSpace.CMYK ,colorValue: [c, m, y, k]};
              } else {
                 if(c != undefined &&  (myColor.properties.colorValue[0] != c || myColor.properties.colorValue[1] != m || myColor.properties.colorValue[2] != y || myColor.properties.colorValue[3] !=k)) {
                      myColor.properties.space = ColorSpace.CMYK;
                      myColor.colorValue = [c, m, y, k];
                  }
              }
              return myColor;
          };
      }
      
      
      
      
      
      
      var diyalogWindow = app.dialogs.add({name: "Rectangle or Textframe"});
      with(diyalogWindow){
        with(dialogColumns.add()){
              with(borderPanels.add()){
                  with(dialogColumns.add()) {
                      staticTexts.add({staticLabel:"Find W"});
                      findW = textEditboxes.add({editContents: "165"});
                  }
                  with(dialogColumns.add()) {
                      staticTexts.add({staticLabel:"Change W"});
                      changeX = textEditboxes.add({editContents: "165"});
                  }
               with(dialogColumns.add()) {
                  staticTexts.add({staticLabel:"Move X"});
                  moveX = textEditboxes.add({editContents: "5"});
              }
           }
              with(borderPanels.add()){
                  with(dialogColumns.add()) {
                      staticTexts.add({staticLabel:"Find H"});
                      findH = textEditboxes.add({editContents: "5"});
                  }
                  with(dialogColumns.add()) {
                      staticTexts.add({staticLabel:"Change H"});
                      changeY = textEditboxes.add({editContents: "5"});
                  }
               with(dialogColumns.add()) {
                  staticTexts.add({staticLabel:"Move Y"});
                  moveY = textEditboxes.add({editContents: "25"});
              }
                   with(dialogColumns.add()) {
                  staticTexts.add({staticLabel:"Page"});
                  pageNo = textEditboxes.add({editContents: myDoc.pages.length.toString()});
              }
           }
         }
      }
      
      if(diyalogWindow.show() == 1)
      {
          var ic = 0;
          var x = Number(moveX.editContents);
          var y = Number(moveY.editContents);
          for (var p = 0; p < app.activeDocument.allPageItems.length; p++)
          {
              var pageItem = app.activeDocument.allPageItems[p];
              pageItem.select();
              var frameSize = pageItem.geometricBounds;
              var frameWidth = frameSize[3]-frameSize[1];
              var frameHeight = frameSize[2]-frameSize[0];
      
      
      
      
              if(Number(Math.round(frameWidth)) == findW.editContents && Number(Math.round(frameHeight)) == findH.editContents)
              {
                  pageItem.geometricBounds = [frameSize[0], frameSize[1], frameSize[0] - Number(changeY.editContents), frameSize[1] + Number(changeX.editContents)];
                  pageItem.move(myDoc.pages[pageNo.editContents - 1]);
                  pageItem.move([x, y + (++ic * 10)]);
              }
          }
      }
      
        • 1. Re: why this command does not work properly
          Jump_Over Level 5
          1.     pageItem.geometricBounds = [frameSize[0], frameSize[1], frameSize[0] - Number(changeY.editContents), frameSize[1] + Number(changeX.editContents)]; 
          2.             pageItem.move(myDoc.pages[pageNo.editContents - 1]); 
          3.             pageItem.move([x, y + (++ic * 10)]); 

           

           

          Hi,

           

          Two things:

          1. (line 1; cosmetic) I would change "frameSize[0] - Number(...)" to "frameSize[0] + Number(...)"

          2. Inbetween lines 2 and 3 above - right after moving pageItem to a page (right one in facing doc) its left-up corner is located in [0,0] point however (somehow) belongs to a left page (can not explain why). If you include additional step (move by):


          pageItem.move(undefined,[10,10]);


          you will see the difference.


          Jarek

          • 2. Re: why this command does not work properly
            hamdifem Level 1

            I did not get the results

             

            pageItem.geometricBounds = [frameSize[0], frameSize[1], frameSize[0] - Number(changeY.editContents), frameSize[1] + Number(changeX.editContents)];

                        pageItem.move(myDoc.pages[pageNo.editContents - 1]);

                        pageItem.move(undefined,[10,10]);

                        pageItem.move([x, y + (++ic * 10)]);

            • 3. Re: Re: why this command does not work properly
              Jump_Over Level 5

              Hi,

               

              What can you see if you place this alert?

               

              //...
              pageItem.move([x, y + (++ic * 10)]);
                alert ("X: " + x +
                "\nY: " + y +
                "\nic: " + ic +
                "\nfSize: " + frameSize +
                "\npName: " + myDoc.pages[pageNo.editContents - 1].name );
              //...
              

               

              Jarek

              • 4. Re: why this command does not work properly
                hamdifem Level 1

                X:25

                Y:25

                ic:2

                fSize:12.7,12.7,17.7,177.7

                pName:12

                • 5. Re: why this command does not work properly
                  hamdifem Level 1

                  does not this also results

                   

                  pageItem.geometricBounds = [frameSize[0], frameSize[1], frameSize[0] + Number(changeY.editContents), frameSize[1] + Number(changeX.editContents)];

                              pageItem.move(myDoc.pages[undefined,pageNo.editContents - 1]);

                              pageItem.move(undefined, [x, y + (++ic * 10)]);

                  • 6. Re: Re: why this command does not work properly
                    Jump_Over Level 5

                    Hi,

                     

                    It is more complex, I am afraid...

                     

                    Notice that after moving a pageItem app.activeDocument.allPageItems is an array with reordered items.

                    Thats why - possibly - you proccess some items twice and some items stay outside of procedure.

                    (in case of line var pageItem = app.activeDocument.allPageItems[p];  is executed inside)

                     

                    Maybe move this line out of loop area:

                     

                    var mPageItems = app.activeDocument.allPageItems;

                    for (var p = 0; p < mPageItems.length; p++) {

                         var pageItem = mPageItems[p];

                         ... and so on

                     

                    Jarek

                    • 7. Re: why this command does not work properly
                      hamdifem Level 1

                      That was the mean trick.

                      why is that  pages 1, 3, 2, 5, 4, 7, 6, 9, 8 shaped marshalled