Skip to main content
Inspiring
October 19, 2022
Answered

Finding superimposed layers.

  • October 19, 2022
  • 1 reply
  • 735 views

Hi everyone.

 

There are T layers in an open document. For some of them, colored pixels of one layer are present in an undefined underlying layer. We need to find such layers. How to do such a trick in manual mode, of course, there is an intersection of the selection areas of two layers, which means that
is the required layer. How to designate such a property using script methods. If( the area of intersection of 2 layers is greater than 0) { place in the array of desired layers} ???

 
This topic has been closed for replies.
Correct answer AnyON
var blackPixels=activeDocument.histogram[0];

Found the following solution
 
var color = new RGBColor()
color.red = 255;
color.blue = 255;
color.green = 255;

app.foregroundColor.rgb = color;

function loadTransparency(){
     var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
        var ref1 = new ActionReference();
        ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
    desc.putReference( charIDToTypeID( "T   " ), ref1 );
     executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}

documents.add(app.activeDocument.width, app.activeDocument.height, app.activeDocument.resolution, "testDoc", NewDocumentMode.RGB)
app.activeDocument.layers[0].isBackgroundLayer = false;
var workDoc = app.documents[0];
var testDoc = app.documents[1];

for (var j = workDoc.layers.length - 1; j > -1; j--) {
     app.activeDocument = workDoc;
     workDoc.activeLayer = app.activeDocument.layers[j];
     var activeLayerName = app.activeDocument.layers[j].name;
     workDoc.activeLayer.copy();
     app.activeDocument = testDoc;
     app.doAction("PastInPlase", "Set 1");
     testDoc.activeLayer.name = activeLayerName;
     loadTransparency();
     testDoc.selection.fill(app.foregroundColor);
     testDoc.selection.deselect();

}
testDoc.layers[testDoc.layers.length - 1].remove();

var f_l_SelectionBaund = undefined;

app.activeDocument.layers[0].blendMode = BlendMode.DIFFERENCE;
loadTransparency();
f_l_SelectionBaund = app.activeDocument.selection.bounds;
app.activeDocument.selection.deselect();

var selectionLayerBaunds = undefined;

for (var i = 1; i < app.activeDocument.layers.length; i++) {
     app.activeDocument.layers[i].visible = false;
}

var needLayers = [];
for (var i = 1; i < app.activeDocument.layers.length; i++) {
     app.activeDocument.layers[i].visible = true;
     app.doAction("GetBlackColor", "Set 1");
     try {
          selectionLayerBaunds = app.activeDocument.selection.bounds;
          if (selectionLayerBaunds != undefined) {
               
               needLayers.push(app.activeDocument.layers[i].name)
          }
     }
     catch(e){}
     app.activeDocument.selection.deselect();
     app.activeDocument.layers[i].visible = false;
}
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert(needLayers);

1 reply

c.pfaffenbichler
Community Expert
Community Expert
October 19, 2022

Please provide a better description and post meaningful screenshots including the Layers Panel to illustrate the situation. 

Are all Layers to be compared against all other Layers, what about Groups and Adjustment Layers, what exactly is the resulting Array supposed to »look like«, …? 

AnyONAuthor
Inspiring
October 19, 2022

link to test file....

https://drive.google.com/file/d/1A24fOCQ9mEfiu3sVQ_OMLYm0ZHqdoW2r/view?usp=sharing 

 

 For Layer 1, the following layers correspond to the described conditions [ Layer 4, Layer 5, Layer 6, Background]

c.pfaffenbichler
Community Expert
Community Expert
October 19, 2022

Thank you. 

 

But what is the resulting Array actually supposed to look like? 

And Array of Arrays with one that lists all Layers that intesect with a Layer, how would that Layer be referenced in the Array within the Array, …?