Checking if layer is visible and run a function depending on answer
Hey guys,
I've got a question that's been racking my brain the last few days.
So I want to run a script when I press a button that will check if a specific layer is visible. If yes, it will execute another function that shows additional layers. If the specific layer is not visible, it checks the next layer to see if that is visible. This continues until it checks all required layers and finds a visible layer.
Here's the script in question:
#target photoshop
//
// clthTopTt.jsx
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== actnStd ==============
//
function checkactnStd() {
// Select
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "actnStd");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(17011);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, dialogMode);
};
// If
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('null'), cTID('Cndt'), cTID('Vsbl'));
var ref1 = new ActionReference();
ref1.putName(cTID('Actn'), "select actnStd"); <------- If the actnStd layer is visible, instead of running this action, it runs the selectactnStd() function.
ref1.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('then'), ref1);
var ref2 = new ActionReference();
ref2.putName(cTID('Actn'), "check actnWlk"); <------- If the actnStd layer is NOT visible, it runs the checks the next layer (via the checkactnWlk() function.
ref2.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('else'), ref2);
executeAction(sTID('conditional'), desc1, dialogMode);
};
step1(); // Select
step2(); // If
};
function selectactnStd() {
// Show
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topStdTt");
ref1.putName(cTID('Lyr '), "topMskStd");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Shw '), desc1, dialogMode);
};
// Hide
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topWlkTt");
ref1.putName(cTID('Lyr '), "topMskWlk");
ref1.putName(cTID('Lyr '), "topRunTt");
ref1.putName(cTID('Lyr '), "topMskRun");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
step1(); // Show
step2(); // Hide
};
//
//==================== actnWlk ==============
//
function checkactnWlk() {
// Select
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "actnWlk");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(17012);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, dialogMode);
};
// If
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('null'), cTID('Cndt'), cTID('Vsbl'));
var ref1 = new ActionReference();
ref1.putName(cTID('Actn'), "select actnWlk");
ref1.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('then'), ref1);
var ref2 = new ActionReference();
ref2.putName(cTID('Actn'), "check actnRun");
ref2.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('else'), ref2);
executeAction(sTID('conditional'), desc1, dialogMode);
};
step1(); // Select
step2(); // If
};
function selectactnWlk() {
// Show
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topWlkTt");
ref1.putName(cTID('Lyr '), "topMskWlk");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Shw '), desc1, dialogMode);
};
// Hide
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topStdTt");
ref1.putName(cTID('Lyr '), "topMskStd");
ref1.putName(cTID('Lyr '), "topRunTt");
ref1.putName(cTID('Lyr '), "topMskRun");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
step1(); // Show
step2(); // Hide
};
//
//==================== actnRun ==============
//
function checkactnRun() {
// Select
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "actnRun");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(17013);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, dialogMode);
};
// If
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('null'), cTID('Cndt'), cTID('Vsbl'));
var ref1 = new ActionReference();
ref1.putName(cTID('Actn'), "select actnRun");
ref1.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('then'), ref1);
var ref2 = new ActionReference();
ref2.putName(cTID('Actn'), "check actnAc");
ref2.putName(cTID('ASet'), "clthTopTt");
desc1.putReference(cTID('else'), ref2);
executeAction(sTID('conditional'), desc1, dialogMode);
};
step1(); // Select
step2(); // If
};
function selectactnRun() {
// Show
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topRunTt");
ref1.putName(cTID('Lyr '), "topMskRun");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Shw '), desc1, dialogMode);
};
// Hide
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "topStdTt");
ref1.putName(cTID('Lyr '), "topMskStd");
ref1.putName(cTID('Lyr '), "topWlkTt");
ref1.putName(cTID('Lyr '), "topMskWlk");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
step1(); // Show
step2(); // Hide
};
After it checks the last layer, it then ends the script.
"clthTopTtLoop.jsx"
// EOF
Any help is seriously appreciated. Thanks guys!
