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

Exclude master objects in a Script

Explorer ,
Mar 16, 2024 Mar 16, 2024

Copy link to clipboard

Copied

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

 

 

TOPICS
How to , Scripting

Views

144

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

Community Expert , Mar 16, 2024 Mar 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]);

 

Votes

Translate

Translate
Community Expert ,
Mar 16, 2024 Mar 16, 2024

Copy link to clipboard

Copied

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

 

Votes

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
Community Expert ,
Mar 16, 2024 Mar 16, 2024

Copy link to clipboard

Copied

LATEST

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

 

Votes

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