Copy link to clipboard
Copied
Hi,
I am looking for how, with a GREP search, to retrieve the number of the column of the searched text, when this one is in a multi-column text frame.
Thanks for your help.
Ronald
It's not possible with GREP to know anything about columns, unfortunately.
It is possible (but not easy) with scripting. (Not easy when span and split column is being used.)
You could try this:
var s = app.documents.item(0).selection[0];
var ho = s.horizontalOffset;
var cc = s.parentTextFrames[0].textFramePreferences.textColumnCount;
var cw = s.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;
var g = s.parentTextFrames[0].textFramePreferences.textColumnGutter;
var x = s.parentTextFrames[0].geometricBounds[1]
for (var i = 0; i < cc; i++){
var cx = i*(cw+g) + x;
if (ho >= cx && ho < cx + cw) {
alert("Selected text starts in column " +
...
Copy link to clipboard
Copied
It's not possible with GREP to know anything about columns, unfortunately.
It is possible (but not easy) with scripting. (Not easy when span and split column is being used.)
Copy link to clipboard
Copied
Hi,
That's what I thought, but maybe someone had the quick fix 🙂
When you say "It is possible (but not easy) with scripting", can you tell me more? I looked at the properties of textframe, story and insersionpoint and couldn't find anything.
Regards
Copy link to clipboard
Copied
You could try this:
var s = app.documents.item(0).selection[0];
var ho = s.horizontalOffset;
var cc = s.parentTextFrames[0].textFramePreferences.textColumnCount;
var cw = s.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;
var g = s.parentTextFrames[0].textFramePreferences.textColumnGutter;
var x = s.parentTextFrames[0].geometricBounds[1]
for (var i = 0; i < cc; i++){
var cx = i*(cw+g) + x;
if (ho >= cx && ho < cx + cw) {
alert("Selected text starts in column " + (i+1))
}
};
Copy link to clipboard
Copied
Cool, merci pour l'aide 😉
Copy link to clipboard
Copied
rob@edidev That's very good. I think I normally use the index property of a textColumn which gives the index of the first character in the column, and then check for that, because relying on horizontal offset is perhaps less reliable for non-rectangular frames.
With span and split columns it gets a lot more complicated though, because (for some reason) each split is considered a separate column.
Copy link to clipboard
Copied
You can do this with a single line:
// With an insertion point 'insPoint'
columnIndex = insPoint.parentStory.insertionPoints.itemByRange (insPoint.parentTextFrames[0].insertionPoints[0].index, insPoint.index).textColumns.length;
Copy link to clipboard
Copied
Thanks Peter, that’s much better.
Copy link to clipboard
Copied
This is master stroke.
Copy link to clipboard
Copied
… How to write a script piece per piece!
Copy link to clipboard
Copied
But not really convinced by the answers given!
It seems to me the matter is more about a geographic localization!
That remembers me about a script of mine written in 2011 and this function "InsertCoordinateMultiPageRefs()" that added "tl" for "top-left", "tr" for "top-right", "bl" for "bottom-left", "br" for "bottom-right" after each "index entry page number", basing on the index entry marker insertion point "horizontalOffset/baseline" values!
Funny!
(^/) The Jedi
Copy link to clipboard
Copied
Peter’s one liner is working with my selected text example:
var insPoint = app.documents.item(0).selection[0].insertionPoints[0];
var columnIndex = insPoint.parentStory.insertionPoints.itemByRange (insPoint.parentTextFrames[0].insertionPoints[0].index, insPoint.index).textColumns.length;
alert("Selected text starts in column " + columnIndex);
Also works with a split column:
Copy link to clipboard
Copied
Aha! In this second case, I would say more: "Damn it! It doesn't work!!! …"
… if I'm only interested by the main parent columns, not the children ones!
(^/)