Table range and note problem
Hi
I wrote a script that finds all table headers and collects the page numbers they are on. Then I check the page number of the next paragraph (table) to see if the table spans more than one page. And everything works fine until there is no footnote reference at the end of the paragraph with the table header - then the next paragraph is the first paragraph of the thread. Do you have any ideas on how to solve this problem?
var doc = app.activeDocument;
var toSearch = app.selection[0].parentStory;
var myTxt = app.selection[0].parentStory.paragraphs;
function main(){
var tableHeadersPages = findTableHeaders();
alert(tableHeadersPages);
}
function findTableHeaders(){
// reset szukania
app.findChangeGrepOptions = null;
app.findChangeTextOptions = null;
app.findTextPreferences = app.changeTextPreferences = null;
app.findGrepPreferences = app.changeGrepPreferences = null;
// nagłówki tabel – numery stron
var tableHeadersPages = [];
app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Rys i Tab").paragraphStyles.item("Tabela H");
var tableHeaders = toSearch.findText();
for (var i = 0; i < tableHeaders.length; i++){
var start = tableHeaders[i].parentTextFrames[0].parentPage.name;
var stop = myTxt.nextItem(myTxt.nextItem(tableHeaders[i])).parentTextFrames[0].parentPage.name;
if (start != stop){
tableHeadersPages.push(start.toString() + '-' + stop.toString());
}
}
return tableHeadersPages;
}
main();I wrote a short test to select the next paragraph and this script is OK.
var myPara = app.selection[0].paragraphs[0];
var myTxt = app.selection[0].parentStory.paragraphs;
myTxt.nextItem(myPara).select();Perhaps the problem is because I used the search tool?
