Hi,
I'm using CS2 JS, and I'm trying to add page references to my index topics.
Here is my code:
var myDoc = app.activeDocument;
var myStory = myDoc.textFrames.item("IndexStory").parentStory;
var index = myStory.associatedXMLElements;
if (myDoc.indexes.length == 0) {
myDoc.indexes.add();
}
for (var i=0; i<index.xmlElements.length;i++) {
var category = index.xmlElements[i];
for (var j=0; j<category.xmlElements.length; j++) {
var element = category.xmlElements[j];
var topicLvl_1;
if (element.markupTag.name == "ati:category.head") {
myDoc.indexes[0].topics.add(element.contents, i.toString());
topicLvl_1 = myDoc.indexes[0].topics[i];
} else {
topicLvl_1.topics.add(element.contents);
markCompany(i, element.contents);
}
}
}
myDoc.indexes[0].update();
function markCompany(sector, companyName) {
app.findPreferences = null;
app.changePreferences = null;
var results = app.search(companyName, true, true, undefined);
for (var i=results.length - 1; i > -1; i--) {
if (results[i].parentTextFrames.length > 0 &&
results[i].parentTextFrames[0].parent.appliedMaster != null &&
(results[i].appliedParagraphStyle.name == "Company Name" ||
results[i].appliedParagraphStyle.name == "Company Headline left just." ||
results[i].appliedParagraphStyle.name == "Company Headline right just.")) {
test = myDoc.indexes[0].topics[sector];
test2 = test.topics.item(companyName);
//InDesign Restarts here
test2.pageReferences.add(results[i], PageReferenceType.currentPage);
}
}
}
on the line after the comment, when ESTK executes that line, InDesign crashes. I'm using a OS X Tiger.
Is this has something to do with the scope of my search? cause when i'm only searching the active document, this does not happen. But I have to search all documents that belong to the book.
Thanks,
Jeff
I'm using CS2 JS, and I'm trying to add page references to my index topics.
Here is my code:
var myDoc = app.activeDocument;
var myStory = myDoc.textFrames.item("IndexStory").parentStory;
var index = myStory.associatedXMLElements;
if (myDoc.indexes.length == 0) {
myDoc.indexes.add();
}
for (var i=0; i<index.xmlElements.length;i++) {
var category = index.xmlElements[i];
for (var j=0; j<category.xmlElements.length; j++) {
var element = category.xmlElements[j];
var topicLvl_1;
if (element.markupTag.name == "ati:category.head") {
myDoc.indexes[0].topics.add(element.contents, i.toString());
topicLvl_1 = myDoc.indexes[0].topics[i];
} else {
topicLvl_1.topics.add(element.contents);
markCompany(i, element.contents);
}
}
}
myDoc.indexes[0].update();
function markCompany(sector, companyName) {
app.findPreferences = null;
app.changePreferences = null;
var results = app.search(companyName, true, true, undefined);
for (var i=results.length - 1; i > -1; i--) {
if (results[i].parentTextFrames.length > 0 &&
results[i].parentTextFrames[0].parent.appliedMaster != null &&
(results[i].appliedParagraphStyle.name == "Company Name" ||
results[i].appliedParagraphStyle.name == "Company Headline left just." ||
results[i].appliedParagraphStyle.name == "Company Headline right just.")) {
test = myDoc.indexes[0].topics[sector];
test2 = test.topics.item(companyName);
//InDesign Restarts here
test2.pageReferences.add(results[i], PageReferenceType.currentPage);
}
}
}
on the line after the comment, when ESTK executes that line, InDesign crashes. I'm using a OS X Tiger.
Is this has something to do with the scope of my search? cause when i'm only searching the active document, this does not happen. But I have to search all documents that belong to the book.
Thanks,
Jeff