Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to check, if primary text frame is used on specific page

Engaged ,
May 31, 2022 May 31, 2022

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

TOPICS
Scripting
383
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 31, 2022 May 31, 2022

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
...
Translate
Engaged ,
May 31, 2022 May 31, 2022

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);
    }
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2022 May 31, 2022

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;
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 31, 2022 May 31, 2022
LATEST

Thanks @rob day, this is an excellent starting point for my needs!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines