Need help adding layer on/off and delete to script...

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

DanielR

Need help adding layer on/off and delete to script...

Post by DanielR »

Hello. Thanks very much for this forum. It has been very helpful. A person here helped me develop a script that check for color in a selection area through layers, and count how many layers have color inside the selected area.

I just need to add a function to this script. (I know nothing of scripting). I need to add this..

When the script is finished, and display how many layers have color inside selection in a popup dialog, text in this popup also asks... "Would you like to make the other layers invisible ? Or do you want to delete them ?", then 3 buttons "Make other layers invisible", "Delete other layers", and "No action".

Here are the code I need to add these functions to.I would greatly appreciate help. Thank you....

-----------------------------------------------------------------------------------------------

//desactiveTransparent.jsx

var docRef = activeDocument;
var calcOpacity = 50; //opacite des calques en %
var num = new Array;
var k = 0;

for ( j=0;j<docRef.layers.length;j++) //masquer tous les calques
{
docRef.layers[j].visible=false;
}
//var Blanc = new SolidColor();
//Blanc.rgb.red=Blanc.rgb.green=Blanc.rgb.blue=255;

if (docRef.layers.length > 1)
{
docRef.layers[docRef.layers.length-1].visible=false; //masque le calque d arriere plan

for(i=0; i < docRef.layers.length-1; i++)
{
docRef.activeLayer = docRef.layers;
docRef.layers.visible = true;

try
{
docRef.selection.selectAll();
docRef.selection.copy();
docRef.selection.deselect();
docRef.layers.visible = false;

}
catch(e) //si la selection est vide : erreur pour copy()
{
docRef.layers.visible = false;
num[k] = i;
k=k+1;
docRef.selection.deselect();
}
}
}

//alert(num)

for(i=0; i < docRef.layers.length - 1; i++) // rend tous les calques visibles
{
docRef.activeLayer = docRef.layers;
docRef.layers.visible = true;
docRef.layers.opacity = calcOpacity;
}

docRef.layers[docRef.layers.length-1].visible=true; //arriere plan visible

for(i=0; i < num.length; i++) // masque les calques selectionnes tout blancs
{
docRef.activeLayer = docRef.layers[num];
docRef.layers[num].visible = false;
}

docRef.activeLayer = docRef.layers[docRef.layers.length-1] //rend l arriere plan actif

var calcVis = (docRef.layers.length - 1) - num.length;
alert( "Calques visibles = " + calcVis );