Copy link to clipboard
Copied
Is it possible to create a script that will search through my document and check if the layer name: "Selection01" exists. if it does, to run the script located in:
D:/Scripts/WorkingScripts/Selection01.jsx
If f the layer name does not exist, to ignore?
Thanks for any help!
Copy link to clipboard
Copied
so the code part is easy. As far as running the other script there are a couple of things you need to do.
First, you need to include that script/ script location into the header of the file. Near the very top of the file add:
#include D:/Scripts/WorkingScripts/Selection01.jsx
this will make sure it loads that portion of the javascript when it loads the rest of the current file.
Second thing you need to do, is to wrap it into a function for execution. Ie.
function Run_Selection01_JSX{
/* do a little dance
do some code
make everyone happy */
}
So, once that is nicely wrapped up into a function, the code for the layer name checking is easy.
if(activeDocument.artLayers.getByName("Selection01"){
Run_Selection01_JSX
} else {
//do nothing,
//do something, its up to you.
}
viola! it should be that easy. unless you need to pass arguments between the new "function" in the selection01.jsx file and the current file your in.
I hope this helps, enjoy ![]()
Copy link to clipboard
Copied
Thanks, d1g1talphyre
....I only need this to run the script..
I'll try to get this to work.
thanks again!
Copy link to clipboard
Copied
function selectLayerByName(name) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc14 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putName( cTID('Lyr '), name );
desc14.putReference( cTID('null'), ref4 );
desc14.putBoolean( cTID('MkVs'), false );
var list1 = new ActionList();
list1.putInteger( 3 );
desc14.putList( cTID('LyrI'), list1 );
executeAction( cTID('slct'), desc14, DialogModes.NO );
if (app.activeDocument.activeLayer.name == name) {
return app.activeDocument.activeLayer;
} else {
return null;
}
};
var layer = selectByName("Selection01");
if (layer) {
// do what you need to do here
}
Copy link to clipboard
Copied
Hi xbytor2,
may I ask you what is the ActionList for, in your snippet? putInteger(3) makes me really curious 🙂
Thank you!
Davide
Copy link to clipboard
Copied
My guess is that's the layer's index, which would be a bit redundant. I'll boot up PS later and see what's going on.
Copy link to clipboard
Copied
It is the layer's index but it is apparently not strictly required. This works:
function selectLayerByName(name) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };var desc14 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putName( cTID('Lyr '), name );
desc14.putReference( cTID('null'), ref4 );
desc14.putBoolean( cTID('MkVs'), false );
executeAction( cTID('slct'), desc14, DialogModes.NO );if (app.activeDocument.activeLayer.name == name) {
return app.activeDocument.activeLayer;
} else {
return null;
}
};
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more