2 Replies Latest reply on Oct 26, 2010 1:47 PM by Cris Ider

    Convert Individual Frames to Multicolumn Text Frames

    Cris Ider Level 1

      Can I Individual Convert Individual Frames to Multicolumn Text Frames?

      I know there is a script to do the inverse:

      http://indesignsecrets.com/convert-multicolumn-text-frames-to-individu al-frames-script.php


      But I need the script to do this:


        • 1. Re: Convert Individual Frames to Multicolumn Text Frames
          [Jongware] Most Valuable Participant
          Can I Individual Convert Individual Frames to Multicolumn Text Frames?



          ... (Apparently not.)


          But it's easy -- if you take various idiosyncrasies into account. What would the height of the new text frame be? The vertical position? The column width and gutter? This script I wrote uses (1) the largest height, (2) the highest top, (3) the average of all columns, and (4) the total width of your selection minus the text frames' accumulated width divided by the number of columns minus 1 (which isn't as nearly as sophisticated as it may sound).


          The script does a few half-hearted tests: are the columns part of one threaded story, are they roughly in left-to-right order, do they overlap. I'm not totally convinced it works absolutely faultless -- make Lots Of Backups because the script may throw away entire textframes, text and all. I didn't try and see what happens with odd-formed text frames.


          theSelection = app.selection;
          if (theSelection.length < 2)
               alert ("Your request does not make sense. Select more frames.\r\r\rBye.");
          for (a=0; a<theSelection.length; a++)
               if (!(theSelection[a] instanceof TextFrame))
                    alert ("Your request doesn't make sense. Select just text frames.\r\r\rBye.");
          if (theSelection.length > 40)
               alert ("Your request doesn't make sense. Select no more than 40 text frames.\r\r\rBye.");
          // Get the ypos -- min of all selected objects
          // Also get the height -- max of all selected objects
          // While we're at it:
          //  Gather left pos and widths
          var leftpos = [ theSelection[0].geometricBounds[1] ];
          var width = [ theSelection[0].geometricBounds[3]-theSelection[0].geometricBounds[1] ];
          var height = theSelection[0].geometricBounds[2]-theSelection[0].geometricBounds[0];
          var ypos = theSelection[0].geometricBounds[0];
          for (a=1; a<theSelection.length; a++)
               leftpos.push ( theSelection[a].geometricBounds[1] );
               width.push ( theSelection[a].geometricBounds[3]-theSelection[a].geometricBounds[1] );
               if (theSelection[0].geometricBounds[0] < ypos)
                    ypos = theSelection[0].geometricBounds[0];
               if (theSelection[a].geometricBounds[2]-theSelection[a].geometricBounds[0] > height)
                    height = theSelection[a].geometricBounds[2]-theSelection[a].geometricBounds[0];
          // Sanity check: left to right, not overlapping
          var totalWidth = width[0];
          for (a=1; a<theSelection.length; a++)
               if (theSelection[a].previousTextFrame != theSelection[a-1] ||
                    leftpos[a-1] > leftpos[a] ||
                    leftpos[a-1]+width[a-1] > leftpos[a])
                    alert ("Those columns are not threaded, or not in the correct order, or overlap!\r\r\rBye.");
               totalWidth += width[a];
          // Convert first textframe into a full-width one
          fullWidth = leftpos[theSelection.length-1]+width[theSelection.length-1] - leftpos[0];
          theSelection[0].geometricBounds = [ ypos, leftpos[0], ypos+height, leftpos[0]+fullWidth ];
          // Add columns ...
          theSelection[0].textFramePreferences.textColumnCount = theSelection.length;
          theSelection[0].textFramePreferences.useFixedColumnWidth = false;
          // .. and set gutter ...
          theSelection[0].textFramePreferences.textColumnGutter = (fullWidth-totalWidth)/(theSelection.length-1);
          // .. and  width ...
          theSelection[0].textFramePreferences.textColumnFixedWidth = totalWidth/theSelection.length;
          // Then kill off other frames.
          for (a=theSelection.length-1; a>0; a--)
          // All done--Bye bye.

          • 2. Re: Convert Individual Frames to Multicolumn Text Frames
            Cris Ider Level 1



            My question has been answered.