Copy link to clipboard
Copied
I don’t have an idea, on how to start a script, which checks every page of a document, if the primary text frame of the master page is used or if it is still »unlocked«. Can someone please give me a hint, where to start this?
Thanks,
Tobias
Hi Tobias , Not sure if someone can come up with something simpler, but try this:
var pgs = app.activeDocument.pages;
var tf, pfs;
for (var i = 0; i < pgs.length; i++){
tf = pgs[i].textFrames;
for (var j = 0; j < tf.length; j++){
if (tf[j].overridden) {
//get an array of primary frame ids from the frame’s master spread
pfs = getPrimaryFrames(tf[j].overriddenMasterPageItem.parent);
//checks if the overridden text frame id is in the primary
...
Copy link to clipboard
Copied
First findings in the API:
var theDoc = app.activeDocument,
thePage = theDoc.pages[7];
var theFrames = thePage.textFrames,
hasOverrides = false;
for ( var i = 0; i < theFrames.length; i++) {
if ( theFrames[i].overridden ) {
hasOverrides = true;
}
}
if ( ! hasOverrides ) {
var thePrimaryTextFrame = thePage.appliedMaster.primaryTextFrame;
if ( thePrimaryTextFrame ) {
thePrimaryTextFrame.override(thePage);
}
}
Copy link to clipboard
Copied
Hi Tobias , Not sure if someone can come up with something simpler, but try this:
var pgs = app.activeDocument.pages;
var tf, pfs;
for (var i = 0; i < pgs.length; i++){
tf = pgs[i].textFrames;
for (var j = 0; j < tf.length; j++){
if (tf[j].overridden) {
//get an array of primary frame ids from the frame’s master spread
pfs = getPrimaryFrames(tf[j].overriddenMasterPageItem.parent);
//checks if the overridden text frame id is in the primary frames array
if (checkItem(pfs, tf[j].overriddenMasterPageItem.id)) {
$.writeln("this text frame is primary")
}
}
};
};
/**
* Get a list of a master spread’s primary text frame’s ids
* @ param the master spread to check
* @ return an array of ids
*
*/
function getPrimaryFrames(ms){
var pf = ms.primaryTextFrame;
var a = [pf.id]
while (pf !=null) {
pf = pf.nextTextFrame;
try {a.push(pf.id)}catch(e) {}
}
return a
}
/**
* Checks if an item is in an array
* @ param the array to check
* @ param the item to look for
* @ return true if the item is in the array
*
*/
function checkItem(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
Copy link to clipboard
Copied
Thanks @rob day, this is an excellent starting point for my needs!