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

Exclude master objects in a Script

Explorer ,
Mar 16, 2024 Mar 16, 2024

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

 

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

 

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 ,
Mar 16, 2024 Mar 16, 2024
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")
    } 
}; 

 

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