• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Retrieve number of the column of searched text

Enthusiast ,
May 24, 2021 May 24, 2021

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.

_Sans_titre-2___43___Aperçu_GPU_.png

Thanks for your help. 

Ronald

TOPICS
Scripting

Views

689

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

People's Champ , May 24, 2021 May 24, 2021

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.)

Votes

Translate

Translate
Community Expert , May 24, 2021 May 24, 2021

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 " +
...

Votes

Translate

Translate
People's Champ ,
May 24, 2021 May 24, 2021

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 24, 2021 May 24, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2021 May 24, 2021

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))
    } 
};   

 

 

Screen Shot 19.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Cool, merci pour l'aide 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 24, 2021 May 24, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2021 May 26, 2021

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Thanks Peter, that’s much better.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

This is master stroke.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 26, 2021 May 26, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2021 May 26, 2021

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);

 

Screen Shot 32.png

 

Also works with a split column:

 

Screen Shot 34.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

LATEST

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!

 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines