Select Layer - Cycle Blend Modes - Return to Initial Active Layer

Engaged ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

Script idea

To cycle through the layer blend modes.

If active layer blende mode is NORMAL make MULTIPLY

If active layer blende mode is DIVIDE make MULTIPLY

If active layer blende mode is COLORBLEND make MULTIPLY

If active layer blende mode is MULTIPLY make NORMAL

 

Script functionality

Get the active layer ID

Select layer MEMO

Cycle layer MEMO blend modes

Reselect the initial layer ID 

 

Video example 1 

The first script cycles the blend modes when the active layer is MEMO. 

 

Screen Shot 2022-06-12 at 10.23.23 AM.png

 

 

#target photoshop
app.bringToFront();

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
Stdlib = function Stdlib() {};

var activeLayer = activeDocument.activeLayer.name; 
var doc = app.activeDocument;
var actLayer = app.activeDocument.activeLayer;
var layerName = actLayer.name;
var targetItem = "MEMO";

var COLORBLEND = BlendMode.COLORBLEND;
var MULTIPLY = BlendMode.MULTIPLY;
var DIVIDE = BlendMode.DIVIDE;
var NORMAL = BlendMode.NORMAL;

try {

  toggelBlendMode();

  function toggelBlendMode() {

    if(actLayer.blendMode == NORMAL || actLayer.blendMode == DIVIDE || actLayer.blendMode == COLORBLEND ) {      
      alert('The blend mode is ' +actLayer.blendMode);
      alert('1')
      app.activeDocument.activeLayer.blendMode = MULTIPLY;
    
    }
    else {
      alert('The blend mode is ' +actLayer.blendMode);
      alert('2')
      app.activeDocument.activeLayer.blendMode = NORMAL;
    }

  }

} catch(e){
  alert( e + ' ' + e.line );
}

 

 

Video example 2

The second script gets that active layer ID selects the layer MEMO, cycles the blend mode, and reselects to the initial layer ID. 

 

Screen Shot 2022-06-12 at 10.20.12 AM.png

 

 

#target photoshop
app.bringToFront();

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
Stdlib = function Stdlib() {};

var activeLayer = activeDocument.activeLayer.name; 
var doc = app.activeDocument;
var actLayer = app.activeDocument.activeLayer;
var layerName = actLayer.name;
var targetItem = "MEMO";

var COLORBLEND = BlendMode.COLORBLEND;
var MULTIPLY = BlendMode.MULTIPLY;
var DIVIDE = BlendMode.DIVIDE;
var NORMAL = BlendMode.NORMAL;
const initLyrID = getLayerID()

try {

  selectLayer(targetItem)

  toggelBlendMode();

  selectLayer(initLyrID)

  function toggelBlendMode() {

    if(actLayer.blendMode == NORMAL || actLayer.blendMode == DIVIDE || actLayer.blendMode == COLORBLEND ) {      
      alert('The blend mode is ' +actLayer.blendMode);
      alert('1')
      app.activeDocument.activeLayer.blendMode = MULTIPLY;
    
    }
    else if(actLayer.blendMode == MULTIPLY) {
      alert('The blend mode is ' +actLayer.blendMode);
      alert('2')
      app.activeDocument.activeLayer.blendMode = NORMAL;
    }

  }

} catch(e){
  alert( e + ' ' + e.line );
}


function getLayerID(){
  var ref = new ActionReference();
  ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') ); 
  return executeActionGet(ref).getInteger(stringIDToTypeID( "layerID" ));
  }
  

  function selectLayer(id, add, viz) {  
    try {
        var d = new ActionDescriptor();
        if (viz == undefined) viz = false;
        var r = new ActionReference();
        if (typeof(id) == "string") r.putName( charIDToTypeID( "Lyr " ), id);
        else                        r.putIdentifier( charIDToTypeID( "Lyr " ), id);
        d.putReference( charIDToTypeID( "null" ), r );
        d.putBoolean( charIDToTypeID( "MkVs" ), viz );
        if (add == true) d.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
        if (add == -1)   d.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "removeFromSelection" ) );
        var ok = true;
        try { executeAction( charIDToTypeID( "slct" ), d, DialogModes.NO ); } catch(e) { ok = false; }
        d = null;
        return ok;
        }
  
    catch (e) { alert(e); return false; }
  }

 

 

Problem

It does not work correctly when the functions selectLayer() and getLayerID() are introduced to select the layer MEMO and reselect the initial active layer. 

 

Error

It does not change the layer MEMO blend mode to NORMAL when the layer is on MULTIPLY 

 

Help

Can someone please help understand if this functionality is possible and if this approach makes sense to cycle the MEMO layer blend mode?

TOPICS
Actions and scripting

Views

66

Likes

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
Adobe Community Professional ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

It's confusing, it's not clear. Lots of extra code.

Why don't you replace

app.activeDocument.activeLayer.blendMode = NORMAL;

with

actLayer.blendMode = NORMAL;

?

 

You check the mode for actLayer, but for some reason change the mode of the app.activeDocument.activeLayer.

 

Likes

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
Engaged ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

I am trying to alert the blend mode of a layer other than the active layer.

For example in a file with two layers, layer 1 and layer 2 and layer 1 as the active layer.

To alert the blend mode of layer 2, it is necessary to select layer 2, then alert that blend mode layer 2. 

 

My impression is that the script alerts the blend mode of the current layer first, then selects layer 2.

Instead of selecting layer 2, then alert the blend mode of layer 2.

 

The result is that the alert is misleading because it shows the blend mode of the current layer (layer1) instead of layer2 which needs to be selected in order to alert the blend mode.

 

In other words, the alert method overrides the select function and displays the blend mode of the current layer instead of the layers that need to be selected first in order to alert its blend mode.

 

Does this make sense?

 

 

 

 

 

 

Likes

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
Adobe Community Professional ,
Jun 14, 2022 Jun 14, 2022

Copy link to clipboard

Copied

LATEST

Ahem... I would help you if I could only understand what you want to do.

 

Nicht verstehen you )

Likes

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