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

Engaged ,
May 31, 2022 May 31, 2022

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

TOPICS
Scripting

Views

46

Likes

Translate

Translate

Report

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

Adobe Community Professional , 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...

Likes

Translate

Translate
Engaged ,
May 31, 2022 May 31, 2022

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

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 31, 2022 May 31, 2022

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

 

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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