Skip to main content
Inspiring
August 3, 2022
解決済み

Anchor position based on columns (scripting)

  • August 3, 2022
  • 返信数 3.
  • 754 ビュー

Hi, is it possible to know in which column you find something using scripting, I then want to anchor an object but it's location depends on the location of the text I find.

Thanks!

このトピックへの返信は締め切られました。
解決に役立った回答 Peter Kahrel

I just realized Story also considers textColumns so I put that instead of frame, I'm just thinking of a way to get the first insertion point of a frame from the story itself so the range isn't from 0 to the selection...


Quite right, I used just one text frame. Here's the correct version:

sel = app.selection[0];
frame = sel.parentTextFrames[0];
$.writeln (frame.parentStory.insertionPoints.itemByRange (
  frame.insertionPoints[0].index, 
  sel.index)
.textColumns.length-1);

 P.

返信数 3

Inspiring
August 4, 2022

Hi @yeshayac 

Loop over the columns of the frame.

In my example I loop over the colums of a selected frame and I find/change in a even column, changing the properties of the searched word.

sel = app.selection[0];
var numCols = sel.textColumns.length;
var mySearch = "IndesignScript";
var myResult;

//Set the find options.
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;

for (i = 0; i < numCols; i++) {
  indexCol = i + 1;
  // Find&Change only in the even columns
  if (indexCol % 2 == 0) {
    app.findTextPreferences.findWhat = mySearch;
    myResult = sel.textColumns[i].findText();
    //Set the properties of myResult
    app.changeTextPreferences.fontStyle = "Bold";
    app.changeTextPreferences.capitalization = Capitalization.ALL_CAPS;
    app.changeTextPreferences.underline = true;
    //Change
    sel.textColumns[i].changeText();
    //Reset find/change
    app.findTextPreferences = app.changeTextPreferences = null;
  }
}

 

yeshayac作成者
Inspiring
August 4, 2022

Thanks! this seems like a good solution, I'm going to try it

yeshayac作成者
Inspiring
August 5, 2022

I ended up going with one of the solutions above because it was easier to implement in what I already had, thanks anyways!

Peter Kahrel
Community Expert
Community Expert
August 4, 2022

And if your columns are text columns, not table columns, you can use something like this:

sel = app.selection[0];
frame = sel.parentTextFrames[0];
$.writeln (frame.insertionPoints.itemByRange (0, sel.index).textColumns.length-1);

P.

yeshayac作成者
Inspiring
August 4, 2022

Yes they are text columns, thanks! I tried this code but I couldn't get it to work passed the first page and I think it's because sel.index is based on the story so it goes out of the range of the frame.insertionpoints

yeshayac作成者
Inspiring
August 4, 2022

I just realized Story also considers textColumns so I put that instead of frame, I'm just thinking of a way to get the first insertion point of a frame from the story itself so the range isn't from 0 to the selection...

Community Expert
August 4, 2022

Hi @yeshayac,

Try the following code by selecting some text in a cell, it will alert the index of the column in which the selection was made. The col variable contains the reference to the column object

var sel = app.selection[0]
if(sel.parent instanceof Cell){
	var col = a.parent.columns[0]
	alert(col.index)
}

-Manan

-Manan