Skip to main content
Known Participant
March 16, 2024
Answered

Exclude master objects in a Script

  • March 16, 2024
  • 2 replies
  • 254 views

How can I exclude TextFrame on MasterPages running the following code?

 

function main() {

        targetFrames = [];
        var doc = app.activeDocument;
       var allTextFrames = doc.textFrames;
        
    // we only want the text frames in specific LAYER
    for (var i = 0; i < allTextFrames.length; i++)
        if (allTextFrames[i].itemLayer.name == targetLayout)
            targetFrames.push(allTextFrames[i]);

 

 

This topic has been closed for replies.
Correct answer m1b

Hi @lux65, you can check if the `parentPage` is on a `MasterSpread`, like this:

var targetFrames = [];
var doc = app.activeDocument;
var allTextFrames = doc.textFrames;

// we don't want text frames on master pages
for (var i = 0; i < allTextFrames.length; i++)
    if ('MasterSpread' !== allTextFrames[i].parentPage.parent.constructor.name)
        targetFrames.push(allTextFrames[i]);

 

2 replies

rob day
Community Expert
Community Expert
March 16, 2024

Hi @lux65 , You can also target the document pages—something like this would skip the text frames on the masters:

 

var tf = app.activeDocument.pages.everyItem().textFrames.everyItem().getElements();

for (var i = 0; i < tf.length; i++){
    if (tf[i].itemLayer.name == "Layer 1") {
        $.writeln("Do Something")
    } 
}; 

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
March 16, 2024

Hi @lux65, you can check if the `parentPage` is on a `MasterSpread`, like this:

var targetFrames = [];
var doc = app.activeDocument;
var allTextFrames = doc.textFrames;

// we don't want text frames on master pages
for (var i = 0; i < allTextFrames.length; i++)
    if ('MasterSpread' !== allTextFrames[i].parentPage.parent.constructor.name)
        targetFrames.push(allTextFrames[i]);