Skip to main content
Inspiring
April 28, 2022
Answered

Apply blending mode to images in group with a script

  • April 28, 2022
  • 2 replies
  • 542 views

I have a long document with many photos. These photos are in groups along with their captions. They currently have the blending mode "Luminosity" applied, but I want them to have "Normal" applied. 

 

I found this script which does exactly what I want with a little modification. But it only works on regular rectangles. If I put the rectangle in a group, the script no longer works on it. Therefore the script doesn't work for my documents because they all have images within groups. How do I modify the script to look within groups?

 

Here's what I have so far:

// the main function
var main = function() {
  var doc = app.activeDocument; // get the current document
  // loop the pages
  for (var i = 0; i < doc.pages.length; i++) { 
    var page = doc.pages[i]; // isolate the page
    // loop all rectangles
    for(var j = 0; j < page.rectangles.length;j++){
      var rect = page.rectangles[j]; // isolate a rectangle
      // test if there is an image inside
      if(rect.images.length > 0){
        var image = rect.images[0]; // isolate the image
        // asign a random color from th swatches
        image.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
      } // end if image
    } // end loop j rectangles
  } // end loop i pages
} // end of main
main(); // run it

Thanks in advance!

 

This topic has been closed for replies.
Correct answer m1b

Hi @23121922udmu, Rob beat me to it, but here's a slightly different approach—just shows there are different ways to reference objects in Indesign. 🙂

- Mark

 

function main() {
    var doc = app.activeDocument,
        graphics = doc.allGraphics;
    for (var i = 0; i < graphics.length; i++) {
        // set blendMode of image
        graphics[i].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        // set blendMode of rectangle
        graphics[i].parent.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        // set blendMode of group
        if (graphics[i].parent.parent.constructor.name == 'Group') {
            graphics[i].parent.parent.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        }
    }
}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set All Graphics to Normal Blend Mode');

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
April 28, 2022

Hi @23121922udmu, Rob beat me to it, but here's a slightly different approach—just shows there are different ways to reference objects in Indesign. 🙂

- Mark

 

function main() {
    var doc = app.activeDocument,
        graphics = doc.allGraphics;
    for (var i = 0; i < graphics.length; i++) {
        // set blendMode of image
        graphics[i].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        // set blendMode of rectangle
        graphics[i].parent.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        // set blendMode of group
        if (graphics[i].parent.parent.constructor.name == 'Group') {
            graphics[i].parent.parent.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
        }
    }
}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set All Graphics to Normal Blend Mode');
Inspiring
April 28, 2022

Thanks so much! This works perfectly. 

rob day
Community Expert
Community Expert
April 28, 2022

Hi @23121922udmu , is the blending mode applied to the group or the images within the group?

 

If it’s the group then this should work:

 

var api = app.activeDocument.allPageItems;

for (var i = 0; i < api.length; i++){
    if (api[i].constructor.name  == "Group") {
        api[i].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL
    } 
}; 

 

 

If it could be to the group’s images or their frames inside of the group, then you might need something like this:

 

var api = app.activeDocument.allPageItems;
var gi, ag;
for (var i = 0; i < api.length; i++){
    if (api[i].constructor.name  == "Group") {
        api[i].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL
        gi = api[i].allPageItems;
        for (var j = 0; j < gi.length; j++){
            gi[j].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL
            ga = gi[j].allGraphics;
            for (var k = 0; k < ga.length; k++){
                ga[k].transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL
            };   
        };   
    } 
};    

 

Inspiring
April 28, 2022

Thank you!!