3 Replies Latest reply on Jun 19, 2017 1:32 AM by Laubender

    Adding objects relativly to the previous object


      Dear all,


      I want to generate 20 objects (the grey ones) with a specific gap in between them and starting relativ to an already present object (the "FoFe" field):

      I'm able to generate those 20 objects but I'm out of ideas to move them below each other.

      My code:


      var myMasterSpread = myDocument.masterSpreads.item(0);
      var TF_FoFe = myMasterSpread.textFrames.add({
      geometricBounds: [60,36,74,60] /*size of Text box*/,
      contents: "FoFe" /*what is written in the text box*/
      }); // end of description of text box
      var myPara2 = TF_FoFe.paragraphs[0];
      myPara2.properties = {
      appliedFont: app.fonts.item("Arial"), // which font is used
      fontStyle: "Bold", // bold or regular or italic
      pointSize: 10, // which font size is used
      justification: Justification.centerAlign // should the text be left, center or right aligned
      }; // end of description of second TextBox 
      for (var a = 0; a < 20; a++) {
      var myY1 = 82;
      var myX1 = 36;
      var myY2 = 96;
      var myX2 = 60;
      var myGap = 8;
      var myTf = myMasterSpread.textFrames.add({
      geometricBounds: [myY1, myX1, myY2, myX2],
      LocationOptions: LocationOptions.AFTER,
      reference: PageItem.PreviousItem


      The PreviousItem thing doesn't work, I'm missing the thing, that it takes into account the objects it created by itself.

      Do you have any ideas? I become desperate...




        • 1. Re: Adding objects relativly to the previous object
          Peter Kahrel Adobe Community Professional & MVP

          next- and previousItem are relevant only in linked objects, such as paragraphs in a story. For threaded frames you'd use previousTextFrame and nextTextFrame, but since you're placing individual frames they're not relevant. You simply place individual frames. I'd do it like this:


          var gb = [82, 36, 96, 60];
          var myGap = 8;  
          myGap = gb[2] - gb[0] + myGap;
          for (var a = 0; a < 20; a++) {
            gb[0] += myGap;
            gb[2] += myGap;
            var myTf = myMasterSpread.textFrames.add ({geometricBounds: gb});


          Define the geometric bounds of the first frame. Then place frames using geometric bounds with the same left and right sides, but adding the gap to the top and bottom bounds. If the gap height is 8, then the second frame is placed such that its top is lower by its height plus the gap.



          1 person found this helpful
          • 2. Re: Adding objects relativly to the previous object
            Cleo_helm Level 1

            Hi Peter,


            with [2] and [0] I target the thrid and first part of my gb-array. I lacked this information.


            Thank you.


            • 3. Re: Adding objects relativly to the previous object
              Laubender Adobe Community Professional & MVP

              Hi Cleo,

              another variant would be to use methods duplicate() where you can advance the duplicate to a new position:

              Adobe InDesign CS6 (8.0) Object Model JS: Rectangle


              First argument not used, second argument defined as array of x/y to define new position with duplicate by argument:

              duplicate( undefined,  [x,y ] )


              var rect = app.documents[0].spreads[0].rectangles.add
                      geometricBounds : [0,0,10,50] ,
                      fillColor : "None"
              var advanceDupsInYby = 20;
              var numOfDups = 5;
              for(var n=0;n<numOfDups;n++)
                  rect.duplicate( undefined , [ 0, (n+1)*advanceDupsInYby ]);