8 Replies Latest reply on Mar 23, 2014 7:49 AM by pixxxel schubser

    Move textFrame to previous position

    Unique Level 1

      Hi Forum,

       

      Need indeed help from you.

       

      After grouping all the pageItems and resizing (scaling) to new page Height, I want to move the text Frames.geometricBounds[1] to the previous position before scaling was done.

       

      for example before scaling: textFrames[i].geometricBounds[1] is 12mm, 16.5mm respectively.

      after grouping and scaling the group to new page height, i want to move back the textFrames.geometricBounds[1] to same 12mm, 16.5 position.

       

      I tried to memorise the geometricBounds[1] of textframes into array and after scaling was done, ungrouped and tried to move all the textframes to the previous position.

       

       

      var tf = app.activeDocument.textFrames.everyItem().getElements();

      for(i=0; i<tf.length; i++) {
      var vat= [];
      vat.push(tf[i].geometricBounds[1].join('\r'));

       

      // here scaling the group is done to new page size...

       

      if (tf[i]].geometricBounds[1]<app.activeDocument.pages.item(0).marginPreferences.left;)

      { tf[i].move([tf[i].parentPage, tf[i].geometricBounds[0]]).

      //trying to move all the textframe to the previous position, when the textframe.geometricBounds[1] are outside the left margin.

      }}

       

      // trying to move all the textframes which are outside the page.bounds[1] marginPreferences.left,  after resizing the document.

       

      Thanks for helping on this.

        • 1. Re: Move textFrame to previous position
          Jump_Over Level 5

          Hi,

           

          1. You have to read 2 textFrame.geometricBounds to get its position, i.e.:

               leftup corner = gb[1] and gb[0] ==> as x nad y

               rightbottom corner = gb[3] and gb[2] ==> as x and y

           

          2. gb[1].join() is trying to execute array's method with a number (error)

          3. did you consider to store textFrame.geometricBounds as its label, so you can get it back anytime you need?

          4. Exam your group.resize method since getting pageItem outside (smaller) page is something weird

           

          Jarek

          • 2. Re: Move textFrame to previous position
            pixxxel schubser Level 5

            Hi Unique,

            at first you should round your text frame position values. Otherwise, it's pretty hard to compare the values.

             

             

            For moving you can try something like this (e.g. for the first text frame):

             

            // http://forums.adobe.com/thread/1434223?tstart=0
            // regards pixxxelschubser
            
            var tf = app.activeDocument.textFrames.everyItem().getElements();
            var oldPosition = [tf[0].geometricBounds[1].toFixed(3),tf[0].geometricBounds[0].toFixed(3)];
            var newPosition = [100,100];
            
            // moving or scaling gives a new position
            tf[0].move(newPosition);
            alert ("move 1");
            
            // back to old position
            tf[0].move(oldPosition);
            alert ("moved to old position");
            

             

            Have fun

             

            • 3. Re: Move textFrame to previous position
              Unique Level 1

              Hello Jarek and pixxxel,

               

              thanks a lot of helping me out.

               

              Let me ask a few questions, if you dont mind.

               

              pixxxel you have assigned tf[0].. is that mean for single text frame...

               

              so can i use your suggestion in for loop to move tf[i] and will that works after the below steps.

              1. storing all the textframes geometric bounds in memory.

              2. resizing the document by grouping all the textframes.

              3. then again moving back the textframes to previous position.

               

              Dear jarek.

               

              1. would be much thanks to you, to have idea to, store each textframes with different lable names.

              2. how could i get gb[0] and gb[1] of textframe without pushing the numbers to array and get them.

              3. sorry for my silly questions.......

               

              many thanks to you2...

              • 4. Re: Move textFrame to previous position
                Jump_Over Level 5

                Hi,

                 

                For each pageItem you can do this (including pixxxell suggestion):

                pageItem.label = 
                     pageItem.geometricBounds[1].toFixed(3) +
                     "|" +
                     pageItem.geometricBounds[0].toFixed(3);
                

                 

                Later on (assuming each pageItem has its label filled like above) you can move their left-up corner to previous position like this:

                 

                pageItem.move( pageItem.label.split("|")[0], pageItem.label.split("|")[1] );
                

                 

                Jarek

                • 5. Re: Move textFrame to previous position
                  pixxxel schubser Level 5

                  Rehi Unique,

                  do you have problems with the loop?

                   

                  Sorry, but IMHO this is really scripting basic knowledge.

                  I'm not an InDesign scripter and that's why I'm not sure, if this is the correct way to loop through all text frame items in an InDesign document.

                   

                  But this example could do what you want.

                  Please give a feedback to me.

                   


                  // textFrames_restorePosition.jsx
                  // http://forums.adobe.com/thread/1434223?tstart=0
                  // regards pixxxelschubser
                  
                  var tf = app.activeDocument.textFrames.everyItem().getElements();
                  var oldPosition = [tf.length];
                  
                  for (i=0; i < tf.length; i++) {
                      // store the old position
                      oldPosition[i] = [tf[i].geometricBounds[1].toFixed(3),tf[i].geometricBounds[0].toFixed(3)];
                  }
                  
                  // insert here your scale or move code instead of this loop
                  var newPosition = [100,100];
                  for (i=0; i < tf.length; i++) {
                      // moving or scaling gives a new position
                      tf[i].move(newPosition);
                  }
                  alert ("move 1");
                  // - - - - -
                  
                  for (i=0; i < tf.length; i++) {
                      // restore the old position
                      tf[i].move(oldPosition[i]);
                  }
                  alert ("moved to old position");
                  

                   

                   

                  Have fun

                   

                  • 6. Re: Move textFrame to previous position
                    Unique Level 1

                    Hello Jarek & pixel.

                     

                    Please see the snapshot attached.

                     

                    My intention is to move the textframes which are outside the page bounds[0], back to the page.

                     

                    when i group the pageitems and scale the text frames goes out the margins. and when running pixxel idea. the text frames goes upside and downside differently.

                     

                    screen shot 1 before page resizing and scaling.

                    before resizing.gif

                    after page resizing and scaling.done.

                     

                    the magenta textframe goes above and cyan text frame comes below. and cyan text frame is not toucing the margin as shown in screen shot 1.

                     

                    I want to visual the same thing after resizing and scaling. just to move the textfrae again to the page.

                     

                     

                    my scribble ugly  works is ;

                     

                    var tf = app.activeDocument.textFrames.everyItem().getElements();
                    for(k=0; k<tf.length;k++) {
                    var oldPosition = [tf[k].geometricBounds[1].toFixed(3), tf[k].geometricBounds[0].toFixed(3)];
                    tf[k].label =
                         tf[k].geometricBounds[1].toFixed(3) +     "|" +     tf[k].geometricBounds[0].toFixed(3);

                    var g = app.activeDocument.pageItems.everyItem();
                    try {
                    var gr = app.activeDocument.groups.add(g);
                    } catch (e) {}
                    var bgr = gr.geometricBounds;
                    var hgr = bgr[2]-bgr[0];

                    // resize document
                    app.activeDocument.documentPreferences.pageWidth = 600;
                    app.activeDocument.documentPreferences.pageHeight = 1200;

                    var pm= gr.parent.marginPreferences;
                    with(pm)
                    {
                    var t = top;
                    var b = bottom;
                        }

                    app.activeDocument.pages.item(0).marginPreferences.top = 15;

                     

                     

                    // scale group to page height
                    var hn = app.activeDocument.pages.item(0).bounds[2] - app.activeDocument.pages.item(0).bounds[0];
                    var s = hn / hgr ;
                    tM = app.transformationMatrices.add({horizontalScaleFactor:s,   verticalScaleFactor:s}); 

                    gr .transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_CENTER_ANCHOR, tM );
                    app.select(gr);

                    //move the scaled item centrally:

                    htt =app.selection[0].geometricBounds[3]-app.selection[0].geometricBounds[1];

                    center = (app.activeDocument.pages.item(0).bounds[3]-htt)/2;

                    gr.move([center, app.activeDocument.pages.item(0).bounds[0]]);

                    app.activeDocument.pages.item(0).groups.everyItem().ungroup();

                     

                    //send back the text frame to previous position, if they are outside the page left margin.

                     

                    tf[k].move([tf[k].label.split("|")[0], tf[k].label.split("|")[1]]);
                    alert ("moved to old position");
                    }

                     

                     

                    Jarek please dont scold me for this ugly work... Im just a beginner...

                    • 7. Re: Move textFrame to previous position
                      Jump_Over Level 5

                      Hi,

                       

                      Try this for resizing last page of doc. Do it with other pages if needed.

                      var 
                           targetPage = app.activeDocument.pages[-1];
                           changedPageSize = [210,180];     // width, height
                           currentPageSize = [
                                targetPage.bounds[3] - targetPage.bounds[1],
                                targetPage.bounds[2] - targetPage.bounds[0] 
                                ];
                           wFactor = changedPageSize[0]/currentPageSize[0];
                           hFactor = changedPageSize[1]/currentPageSize[1]; 
                           mGroup = targetPage.groups.add( targetPage.allPageItems );
                                          
                           targetPage.resize(
                                CoordinateSpaces.INNER_COORDINATES, 
                                AnchorPoint.TOP_LEFT_ANCHOR, 
                                ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
                                [wFactor, hFactor]);
                           mGroup.resize(
                                CoordinateSpaces.INNER_COORDINATES, 
                                AnchorPoint.TOP_LEFT_ANCHOR, 
                                ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
                                [wFactor, hFactor]);
                      

                       

                      Jarek

                      • 8. Re: Move textFrame to previous position
                        pixxxel schubser Level 5

                        Unique wrote:

                         

                        … After grouping all the pageItems and resizing (scaling) to new page Height, I want to move the text Frames.geometricBounds[1] to the previous position before scaling was done.

                         

                        for example before scaling: textFrames[i].geometricBounds[1] is 12mm, 16.5mm respectively.

                        after grouping and scaling the group to new page height, i want to move back the textFrames.geometricBounds[1] to same 12mm, 16.5 position.

                         

                        I tried to memorise the geometricBounds[1] of textframes into array and after scaling was done, ungrouped and tried to move all the textframes to the previous position

                        For your (first) posting my last script could help.

                         

                         

                         

                        But not for this:

                        Unique wrote:

                         

                        My intention is to move the textframes which are outside the page bounds[0], back to the page …

                         

                        I want to visual the same thing after resizing and scaling. just to move the textfrae again to the page …

                         

                        Sorry. But this are completely different requirements.

                         

                        1 person found this helpful