How to override multiple named textframes only through script
- May 12, 2024
- 1 reply
- 676 views
I have a script handy which overrides a textframe in document pages.
Process is, I go the the master page and select the text frame I want to be overriden from the document pages. Apply "bluepara" parastyle for blue and "yellowpara" parastyle yellow boxes.
Here is the overriding script I am using:
function main() {
var doc = app.activeDocument;
var sel = doc.selection[0];
if (
sel == undefined
|| !sel.isValid
|| !sel.hasOwnProperty('parentPage')
|| sel.parentPage.parent.constructor.name !== "MasterSpread"
) {
alert("Error\rSelect exactly one item on a master page and try again.");
return;
}
var masterSpread = sel.parentPage.parent,
counter = 0;
for (var i = 0; i < doc.pages.length; i++) {
var page = doc.pages[i];
if (page.appliedMaster == masterSpread) {
try {
sel.override(page);
counter++;
} catch (error) {
// item doesn't exist on that page
}
}
}
alert('The selected item was overridden on ' + counter + ' pages.')
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Override Selected Master Page Item');
The script works fine if I have selected just 1 text frame. It does not work for multiple textframe. Ideally it should.
I am doing it individually currently. After that I run another script to put a particular special charater in that text frame.
Here is the another script:
myDoc = app.documents[0];
var txtFrame = myDoc.textFrames.everyItem().getElements();
for(var i = 0 ; i < txtFrame.length; i++){
if(txtFrame[i].name == "blue"){
txtFrame[i].insertionPoints[-1].contents = SpecialCharacters.ZERO_WIDTH_NONJOINER;
}
}
for(var i = 0 ; i < txtFrame.length; i++){
if(txtFrame[i].name == "yellow"){
txtFrame[i].insertionPoints[-1].contents = SpecialCharacters.ZERO_WIDTH_NONJOINER;
}
}
I have named the textframes as "blue" and "yellow". There are other textframes also. I just want blue and yellow to be overridden and populated with the special character.
How can I combine both in a single script and it should work for named textframes "blue" and "yellow" only and ignore other textframes.
I have attached the idml file.
