title: InDesign - Add column numbers and row letters text under an set of images
body: <p>I'm stuck with a script and can't find a solution online, hope someone can help me.<br />
  In the place where I work, we print on the tiles. One of the main jobs consist in splitting a large image into several squares and print them on tiles like this:
  <a href="https://i.stack.imgur.com/AX7Rl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AX7Rl.jpg" alt="" /></a></p>
  <p>Then the tiler will install the tiles by joining them to form the image. To do this he must have some indications on how to place the tiles.<br />
  We usually use a grid like the one in the battleship game, with letters on one side and numbers on the other like the red ones you see in the image (e.g. A1, A2...).<br />
  They would not be inside the image, it's just for reference.<br />
  I have put together a script to place the square images one per page of an InDesign document, now what I am looking for is insert some text under the images where it marks which tile it is (e.g. A1, C5 ...).<br />
  There is a way to manually choose a custom number for the number of horizontal tiles (e.g. 4) so that the script inserts the text A1 to A4, and then starts inserting the letter B all the way to B4, then C, D, etc. etc. until the tile images runs out?<br />
  Here is my script so far:</p>
  <pre><code>    var Pagewidth =app.activeDocument.documentPreferences.pageWidth;
      var Pageheight = app.activeDocument.documentPreferences.pageHeight;
      var Imagefolder = Folder.selectDialog(&quot;Select a folder&quot;);
      var Images = Imagefolder.getFiles(/.+\.(?:gif|jpe?g|eps|tiff?|psd|pdf|bmp|png)$/i);
      for(var i =0; i &lt; Images.length; i++) {
          var Placed = app.activeDocument.pages.item(-1).place(Images[i]);
          app.activeDocument.align(Placed[0], AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
          app.activeDocument.align(Placed[0], AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
          Placed[0].parent.fit(FitOptions.FRAME_TO_CONTENT);
          app.activeDocument.pages.add(LocationOptions.AT_END);
          }
      app.activeDocument.pages.item(-1).remove();
  </code></pre>
  <hr />
  <p><strong>EDIT</strong></p>
  <p>Just in case I'll try to be more clear, what I'm looking for is adding some text under the images on every page, like this:</p>
  <p><a href="https://i.stack.imgur.com/SB2lt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SB2lt.jpg" alt="" /></a></p>
  <p>I already know how to add the textframe for every image and place it under them.<br />
  What don't understand is how to add this kind of textframe content.</p>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>Thanks to the code provided by Yuri, I adapted it for my purposes.<br />
  Here is the final code:</p>
  <pre><code>    var Pagewidth =app.activeDocument.documentPreferences.pageWidth;
      var Pageheight = app.activeDocument.documentPreferences.pageHeight;
      var Columns = prompt(&quot;Type the number of columns&quot;,&quot;&quot;);
      if(!Columns){
          exit();
          }
      if(!Number(Columns)){
          alert(&quot;You can only type numbers&quot;);
          exit();
          }
      var Imagefolder = Folder.selectDialog(&quot;Select a folder&quot;);
      if(!Imagefolder){
          exit();
          }
      var Images = Imagefolder.getFiles(/.+\.(?:gif|jpe?g|eps|tiff?|psd|pdf|bmp|png)$/i);
      for(var i =0; i &lt; Images.length; i++){
          var Placed = app.activeDocument.pages.item(-1).place(Images[i]);
          app.activeDocument.align(Placed[0], AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
          app.activeDocument.align(Placed[0], AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
          Placed[0].parent.fit(FitOptions.FRAME_TO_CONTENT);
          app.activeDocument.pages.add(LocationOptions.AT_END);
          }
      app.activeDocument.pages.item(-1).remove();
      var Lettersnumber = 26;
      var Arr = [];
      var Letters = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;
      for(var j = 0; j &lt; Lettersnumber; j++){
          for(var k = 1; k &lt;= Columns; k++){
              Arr.push(Letters[j] + k);
              }
          }
      for(var l = 0; l &lt; app.activeDocument.allGraphics.length; l++){
          if(app.activeDocument.allGraphics[l].parentPage != null){
              try{
                  var Subtext = app.activeDocument.allGraphics[l].parentPage.textFrames.add();
                  Subtext.textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN;
                  Subtext.contents = Arr[l];
                  Subtext.paragraphs[0].appliedFont = app.fonts.item(&quot;Arial&quot;);
                  Subtext.paragraphs[0].pointSize = &quot;30&quot;;
                  Subtext.paragraphs[0].justification = Justification.CENTER_ALIGN;
                  var Margin = app.activeDocument.allGraphics[l].parent.visibleBounds;
                  Subtext.visibleBounds = [Margin[2]+12, Margin[1], Margin[2]+4, Margin[3]];
                  Subtext.fit(FitOptions.FRAME_TO_CONTENT);
                  Subtext.fit(FitOptions.FRAME_TO_CONTENT);
                  Subtext.move(undefined, [&quot;0&quot;, &quot;12&quot;]);
                  }
              catch(e){
                  alert(&quot;The text is not enough for the number of images in the document&quot;);
                  break;
                  }
              }
          }
  </code></pre>