Skip to main content
Inspiring
August 21, 2011
Answered

Combine by Blend Mode?

  • August 21, 2011
  • 1 reply
  • 1043 views

I have a tedious production task I'd love help automating.

I receive layouts with mutliple layers of product shots (with transparency) in Normal blend mode. Most of those layers also have separate shadow layers in Multiply blend mode. (Sometimes these layers have masks, othertimes not.) Depending on how the file was built, product layers might be in proximity of their shadow layers, or they may not, making organization and contraction challenging.

(In case it matters, sometimes all layers (products and shadows) are housed inside a single group, sometimes there are no groups at all.)

Ultimately, I'd like to merge all the Product layers into one Normal mode layer, and all the Shadow layers into one Multiply mode layer (with masks applied), with the two layers linked to each other.

Can layers be identified and merged according to blend modes?

This topic has been closed for replies.
Correct answer c.pfaffenbichler

This might work.

But this disregards possible masks on groups and just moves the Multiply artLayers into one group and all others into another.

// move all artlayers set to multiply and all other artlayers into two layersets and then merge those;

// 2011; use it at your own risk;

#target photoshop;

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var artLayers = collectLayers(myDocument);

var multiplyGroup = myDocument.layerSets.add();

multiplyGroup.name = "multiply";

multiplyGroup.blendMode = BlendMode.MULTIPLY;

var normalGroup = myDocument.layerSets.add();

normalGroup.name = "normal";

for (var m = 0; m < artLayers.length; m++) {

     var thisLayer = artLayers;

     if (thisLayer.blendMode == BlendMode.MULTIPLY) {

          thisLayer.move(multiplyGroup, ElementPlacement.PLACEATBEGINNING)

          }

     else {

          thisLayer.move(normalGroup, ElementPlacement.PLACEATBEGINNING)

          }

     };

normalGroup.merge();

multiplyGroup.merge();

};

////////////////////////////////////

////////////////////////////////////

////////////////////////////////////

////// function collect all layers //////

function collectLayers (theParent) {

     if (!allLayers) {

          var allLayers = new Array}

     else {};

     for (var m = theParent.layers.length - 1; m >= 0;m--) {

          var theLayer = theParent.layers;

// apply the function to layersets;

          if (theLayer.typename == "ArtLayer") {

// exclude background layer;

               if (theLayer.isBackgroundLayer == false) {

                    allLayers.push(theLayer)

                    }

               }

          else {

               allLayers = allLayers.concat(collectLayers(theLayer))

// this line includes the layer groups;

//               allLayers.push(theLayer);

               }

          };

     return allLayers

     };

1 reply

c.pfaffenbichler
Community Expert
Community Expert
August 22, 2011
Can layers be identified and merged according to blend modes?

Yes, they can be identified and based on that could be moved onto two separate groups and those merged (flattening the group would naturally apply the Layer Masks if they are not turned off).

The possible risk I see is if Layers are originally in Groups and the Groups have Layer Masks – checking for that would make the matter somewhat more complicated.

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
August 22, 2011

This might work.

But this disregards possible masks on groups and just moves the Multiply artLayers into one group and all others into another.

// move all artlayers set to multiply and all other artlayers into two layersets and then merge those;

// 2011; use it at your own risk;

#target photoshop;

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var artLayers = collectLayers(myDocument);

var multiplyGroup = myDocument.layerSets.add();

multiplyGroup.name = "multiply";

multiplyGroup.blendMode = BlendMode.MULTIPLY;

var normalGroup = myDocument.layerSets.add();

normalGroup.name = "normal";

for (var m = 0; m < artLayers.length; m++) {

     var thisLayer = artLayers;

     if (thisLayer.blendMode == BlendMode.MULTIPLY) {

          thisLayer.move(multiplyGroup, ElementPlacement.PLACEATBEGINNING)

          }

     else {

          thisLayer.move(normalGroup, ElementPlacement.PLACEATBEGINNING)

          }

     };

normalGroup.merge();

multiplyGroup.merge();

};

////////////////////////////////////

////////////////////////////////////

////////////////////////////////////

////// function collect all layers //////

function collectLayers (theParent) {

     if (!allLayers) {

          var allLayers = new Array}

     else {};

     for (var m = theParent.layers.length - 1; m >= 0;m--) {

          var theLayer = theParent.layers;

// apply the function to layersets;

          if (theLayer.typename == "ArtLayer") {

// exclude background layer;

               if (theLayer.isBackgroundLayer == false) {

                    allLayers.push(theLayer)

                    }

               }

          else {

               allLayers = allLayers.concat(collectLayers(theLayer))

// this line includes the layer groups;

//               allLayers.push(theLayer);

               }

          };

     return allLayers

     };

s_mahnAuthor
Inspiring
August 22, 2011

hey thanks. i might not get acess to the needed files for a couple of days but i'm excited to give this a try. thanks again.