Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
columnIndex = i;
break;
}
alert(columnIndex);
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Good one Peter!
Ken, give him the star!
Harbs
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ken -- I've no idea. What's your selection?
Copy link to clipboard
Copied
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?