8 Replies Latest reply on Jan 7, 2012 6:11 AM by Jump_Over

    Spreads/pages index mess

    Jump_Over Level 5

      hello,

      Could you help me to find a mistake?

      There is 40 pages created (IDCS5) in spreads with 4 pages inside every one (1-4, 5-8, etc).

      If I try to add an object, say rectangle, to first or second page - both are set on 1st page.

      myRec = myDoc.spreads[0].pages[2].rectangles.add() - gives rect on page 2nd.

      myRec = myDoc.spreads[0].pages[3].rectangles.add()  - gives rect on page 3rd.

      myRec = myDoc.spreads[0].pages[4].rectangles.add()  - gives error.

      myRec = myDoc.pages[4].rectangles.add()  - gives rect on page 5th.

      myDoc.pages[3].select()   or   myDoc.spreads[0].pages[3].select()   -   gives a selection of correct (4th) page.

       

      Where should I look for reason of that?

       

      myDoc was created using:

       

      for(k=0;k<10;k++){

          while (myDoc.spreads[k].pages.length<4){

          myDoc.spreads[k].pages.add(LocationOptions.atBeginning, myDoc.spreads[k]);

          }

          myDoc.spreads.add();

          myDoc.spreads[k+1].properties = {allowPageShuffle: false};

          }

      myDoc.spreads[-1].remove();

       

       

      THX

        • 1. Re: Spreads/pages index mess
          John Hawkinson Level 5

          Could you help me to find a mistake?

          There is 40 pages created (IDCS5) in spreads with 4 pages inside every one (1-4, 5-8, etc).

          If I try to add an object, say rectangle, to first or second page - both are set on 1st page.

          myRec = myDoc.spreads[0].pages[2].rectangles.add() - gives rect on page 2nd.

          myRec = myDoc.spreads[0].pages[3].rectangles.add()  - gives rect on page 3rd.

          myRec = myDoc.spreads[0].pages[4].rectangles.add()  - gives error.

          Seems clear enough! pages is zero-indexed. The first spread has four pages, .pages[0] through .pages[3]. So .pages[4] is out of bounds.

          • 2. Re: Spreads/pages index mess
            Jump_Over Level 5

            Know that. Point is that I can't set object on the last page of each spread (spread[k].page[3].)

             

             

            I can create object there but next step, when I set geometricBounds - object goes to the page before. Thats why on page[0] I have those created on page[1] and page[0].

             

            zeroPoint is set to [0,0] and rulerOrigin is set to pageOrigin.

             

            In those settings geometricBounds, say [10,10,100,100] moves object to the page before. So there is empty page[3] and duplicated objects on page[0].

             

            If I set rulerOrigin to spreadOrigin and multiple pageWidth in geometricBounds - its works correct.

            But...

            • 3. Re: Spreads/pages index mess
              John Hawkinson Level 5

              It's a little too hard to help you.

               

              If I add myDoc=app.activeDocument; to the beginning of your script and run it, it goes in an infinite loop and creates hundreds of pages and I have to quit InDesign.

               

              Give  a clear reproducible test case and show  what the problem is, please.

              • 4. Re: Spreads/pages index mess
                Jump_Over Level 5

                Sorry, first point is I talk about this with real mess.

                But use this snipp, pls.

                ___________________________________________________________

                myDoc = app.activeDocument;

                 

                myDoc.spreads[0].properties = {allowPageShuffle: false};

                myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

                myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

                myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

                myDoc.zeroPoint = [0,0];

                 

                for(k=0;k<3;k++){

                    while (myDoc.spreads[k].pages.length<4)

                    myDoc.spreads[k].pages.add();

                    myDoc.spreads.add();

                    myDoc.spreads[k+1].properties = {allowPageShuffle: false};

                    }

                myDoc.spreads[-1].remove();

                 

                 

                myCreateParentPa = new Array();

                myFinalParentPa = new Array();

                 

                for (i = 0; i <4; i++){

                    myTF = myDoc.pages[i].textFrames.add();

                    myCreateParentPa.push(myTF.parentPage.index);

                    myTF.geometricBounds = [10,10,100,100];        // at this point I hope to stay on the same page

                    myFinalParentPa.push(myTF.parentPage.index);

                    }

                 

                alert(myCreateParentPa + "\r" + myFinalParentPa)  // [0,1,2,3] vs [0,0,1,2]

                 

                _____________________________________________________________

                 

                So it looks like TF created on page has geometricBounds (y,x) out of page and if I set my geoBounds TF moves to page before. Why?

                • 5. Re: Spreads/pages index mess
                  கற்பனை (Imagine) Level 3

                  Textframes are created on the pages but it's all above the margin of the page.  Textframe geometricBounds properties accept the array of four values like "top, left, bottom, right", or [y1, x1, y2, x2].  You have to concentrate to positioning the textframes by using the values of geometricBounds.

                   

                  I hope this help to you.

                  • 6. Re: Spreads/pages index mess
                    Jump_Over Level 5

                    OK, the last part of snipp is modified:

                     

                    __________________

                    ....

                    myCreateParentPa = new Array();

                    myFinalParentPa = new Array();

                     

                    for (i = 0; i <4; i++){

                        myTF = myDoc.pages[i].textFrames.add({geometricBounds: [10,10,100,100]}); 

                                                                                               // should I expect to have TF on page[i] ?

                        myCreateParentPa.push(myTF.parentPage.index);

                        myTF.geometricBounds = [20,20,100,100];        // at this point I hope to stay on the same page

                        myFinalParentPa.push(myTF.parentPage.index);

                        }

                     

                    alert(myCreateParentPa + "\r" + myFinalParentPa)  // [0,0,1,2] vs [0,0,1,2]

                     

                    ______________________________

                     

                    Are geometricBounds correspond to RulerOrigin.pageOrigin?

                    Or should I always assume, that [0,0] point start on page[0] and use pageWidth to set objects geoBounds on pages deep inside of spread?

                    • 7. Re: Spreads/pages index mess
                      கற்பனை (Imagine) Level 3

                      Jump_Over wrote:

                       

                      Are geometricBounds correspond to RulerOrigin.pageOrigin?

                      Or should I always assume, that [0,0] point start on page[0] and use pageWidth to set objects geoBounds on pages deep inside of spread?

                       

                      Yes.  geometricBounds are correspond to the page ruler origin.   i think you have some logic errors.  You have to create the textframe on page with your specified width and height.  then use the move() method to moving the textframes on page where you need to place.  Move() method accept the array of X and Y coordinates.

                       

                      Hope this helps to you.

                      • 8. Re: Spreads/pages index mess
                        Jump_Over Level 5

                        there is no Height and Width property of TF cause its taken from calculation of geoBounds.

                        If I use geoBounds TF moves to previous page.

                        If I use move({to:}) method before setting geoBounds - TF moves to previous page.

                        If I use move({,by:}) method (push TF from left up corner) and set geoBounds after this - TF stay on correct page.

                         

                        It is nothing critical, but to be honest with logic - TF created on page[k] with RulerOrigin set to pageOrigin

                        should stay on page[k] when I use (plus value) geoBounds to set the size and position.

                        If default position of page[k].object.add() is out of page[k] - thats logic error, or explain me, pls, where am I wrong.