5 Replies Latest reply on Aug 25, 2010 4:07 PM by Cris Ider

    Column number

    Cris Ider Level 1

      Hi!

       

      I´m trying automate my Indesign CS5 without create paragraphs, caracter and object styles.

       

      I need a script increase/decrease a number columns.

       

      Somthings like..

       

      One text frame selected by Selection Tool (NOT type tool) with 1 column and so I apply a script and result a frame with 2 column, apply the script again and 3 column on and on. Other script to decrease column till this frame comes 1 column.

       

       

      Is it possible? (Sorry for my english)

       

      Thanks!!!

        • 1. Re: Column number
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          This will add columns to your text frame:

           

          var mySel = app.selection[0];
          if(mySel instanceof TextFrame){
              try{mySel.textFramePreferences.textColumnCount += 1;}
              catch(_){}
          }
          

           

          This will remove columns from your text frame:

           

          var mySel = app.selection[0];
          if(mySel instanceof TextFrame){
              try{mySel.textFramePreferences.textColumnCount -= 1;}
              catch(_){}
          }
          

           

          Hope it helps

           

          --

          tomaxxi

          http://indisnip.wordpress.com/

          • 2. Re: Column number
            [Jongware] Most Valuable Participant

            app.selection[0].textFramePreferences.textColumnCount++;

             

            As per your previous question, you ask for "One text frame selected by Selection Tool (NOT type tool)". You cannot select a text frame with the text tool -- or (an alternative interpretation) the text frame is selected automatically when you click a text cursor in it. But it's easy to have this script, and the other one Tomaxxi wrote for you, react on the type of user selection.

            You can always check the type of selection immediately for any of ID's objects using "instanceof":

             

            if (app.selection[0] instanceof TextFrame)

              app.selection[0].textFramePreferences.textColumnCount++;

            else

              alert ("Please select a text frame first!");

             

            You can also have the script select the "smart" option: if your cursor is in a text and you run the script anyway, chances are you intended to increase the column count. Since the cursor is inside text, you can do something like this:

             

            if (app.selection[0] instanceof InsertionPoint)

            app.selection[0].parentTextFrames[0].textFramePreferences.textColumnCount++;

            else

            alert ("Please select a text frame first");

             

            .. but it has some drawbacks. The "app.selection[0]" will adjust its type to what is actually selected -- if the cursor is idly blinking between two characters it is an InsertionPoint; you can have one or more characters selected, then it's Character. If you happen to have one entire word selected, it's Word. If you have one entire line selected, it's Line; and if you selected an entire paragraph, well, it's Paragraph. (I didn't test but it's probably Story if you selected everything.)

            Fortunately, you don't have to check each and every possibility. All of these text objects have something in common: they all have a parentTextFrame. You can check if something "has" a certain property with the command "hasOwnProperty". So, a good way to test if you can change the column count of a frame (regardless what the cursor is pointing to) is

             

            if (app.selection[0] instanceof TextFrame)

              app.selection[0].textFramePreferences.textColumnCount++;

            else

              if (app.selection[0].hasOwnProperty("parentTextFrames"))

                app.selection[0].parentTextFrames[0].textFramePreferences.textColumnCount++;

              else

                alert ("Please select a text frame first");

            • 3. Re: Column number
              Cris Ider Level 1

              Thanks again!!!

              • 4. Re: Column number
                Cris Ider Level 1

                Thank you for your additional help.

                • 5. Re: Column number
                  Marijan Tompa [tomaxxi] Level 4

                  Great explanation Jongware!

                   

                  Just one thing, if you add columns with ++ you also need to check number of columns, because maximum is 40, also when you remove, you can't go below 1, so be sure you check it before applying new value.

                   

                  --

                  tomaxxi

                  http://indisnip.wordpress.com/