10 Replies Latest reply on Jun 4, 2010 12:37 PM by Ken Krugh

    Text Column of Selection

    Ken Krugh Level 1

      I THOUGHT that recently I had found a way to get the text column number that an insertion point was in. In a 2-column text frame I was getting (I THOUGHT!) 1 or 2.

       

      Now I can't seem to find how I was doing it! I thought it would have been Ind.Selection(1).Insertionpoints(1).TextColumns(1).Index but I'm getting numbers like 56400 and 57393!

       

      Any help would be appreciated.

       

      Ken

        • 1. Re: Text Column of Selection
          TᴀW Adobe Community Professional & MVP

          You could use the HorizontalOffset property to get the x-value of the leftmost edge of the column you're in. Seeing as all columns have the same width, it shouldn't be too difficult to figure out which you're in.

          1 person found this helpful
          • 2. Re: Text Column of Selection
            Harbs. Level 6

            Something like this:

             

            textFrame = text.parentTextFrames[0];

            textColumns = textFrame.textColumns;

            curColumn = text.textColumns[0];

            columnIndex = NaN;

            for(i=0;i<textColumns.length;i++){

                 if(curColumn==textColumns[i];

                 columnIndex = i;

                 break;

            }

            alert(columnIndex);

            1 person found this helpful
            • 3. Re: Text Column of Selection
              Ken Krugh Level 1

              Thanks guys! Not knowing just what the .Index was returning I ended up using a combo of sorts, looping through the columns looking at the horizontal offsets of the columns and my insertion point.

               

              One point of note I hadn't realized until working on another section of this same script was that .TextFrames(1).TextColumns.Count returns the number of columns in which the text is flowing, NOT the number of columns defined in the frame. It returns specifically only the number of columns in which the text is flowing. Using .TextFrames(1).TextFramePreferences.TextColumnCount gives, of course, the number of columns defined in the frame.

               

              Forever learning,

              Ken

              • 4. Re: Text Column of Selection
                Ken Krugh Level 1

                One more note on this that someone, somewhere may find useful.

                 

                When I found ...TextFrame.TextColumns(1).HorizontalOffset in the object model (VB6, InD CS3) I assumed it was the boundary of the column. It is actually the boundary of the text within the column (which actually makes sense from the name), more specifically, the FIRST TEXT LINE in that column. So only when the text sits flush left with no indention does it return the actual boundary of the column.

                 

                ...TextFrame.TextColumns(1).EndHorizontalOffset seems to return the right side of the LAST line of text in that column.

                 

                Thanks again for the help,

                Ken

                • 5. Re: Text Column of Selection
                  Harbs. Level 6

                  Why are you using the horizontalOffset? That seems like a very roundabout way to find what you want. Doesn't my function do exactly what you wanted?

                   

                  Harbs

                  • 6. Re: Text Column of Selection
                    Peter Kahrel Adobe Community Professional & MVP

                    How about this one-liner:

                     

                    myText.parentTextFrames[0].characters.itemByRange (0, myText.index).textColumns.length;

                     

                    That gives you the VB number (first column is 1). For JS, add -1 at the end (first column = 0).

                     

                    Peter

                    • 7. Re: Text Column of Selection
                      Harbs. Level 6

                      Good one Peter!

                       

                      Ken, give him the star!

                       

                      Harbs

                      • 8. Re: Text Column of Selection
                        Ken Krugh Level 1

                        Hi Peter,

                         

                        Getting back to this as part of another script, I wasn't able to get your brilliant one liner to work last time I was fiddling with this.

                         

                        How do I define myText? I was trying to use Selection(1) like so:

                         

                             TxtColNum = InD.Selection(1).ParentTextFrames(1).Characters.ItemByRange(1, InD.Selection(1).Index).TextColumns.Count

                         

                        but I'm getting an error that an argument is not optional, though I can't for the life of me figure out which argument is missing.

                         

                        Thanks,

                        Ken

                        • 9. Re: Text Column of Selection
                          Peter Kahrel Adobe Community Professional & MVP

                          Ken -- I've no idea. What's your selection?

                          • 10. Re: Text Column of Selection
                            Ken Krugh Level 1

                            Thanks for having a look Peter. The script acts on the paragraphs in the

                            selected text so our operators will just quickly swipe some text making

                            sure they've included all the paragraphs necessary. Make sense?