-
1. Re: Search if a layersets with a specific name exist and execute a function if it is the case
c.pfaffenbichler Oct 15, 2014 7:09 AM (in response to Sebastien Piconnier)Are you comfortable with Action Manager code or do you prefer DOM code?
-
2. Re: Search if a layersets with a specific name exist and execute a function if it is the case
Sebastien Piconnier Oct 15, 2014 7:20 AM (in response to c.pfaffenbichler)javascript Extendscript
-
3. Re: Search if a layersets with a specific name exist and execute a function if it is the case
c.pfaffenbichler Oct 15, 2014 7:34 AM (in response to Sebastien Piconnier)That seems to indicate that you did not understand what I was talking about.
Document Object Model code is usually better to read but runs slower and encompasses fewer of Photoshop’s functionalities than Action Manager code (the kind one can record with ScriptingListener.plugin).
-
4. Re: Search if a layersets with a specific name exist and execute a function if it is the case
Sebastien Piconnier Oct 15, 2014 7:44 AM (in response to c.pfaffenbichler):-) Scripting is a hobby for me. I'm not a professional :-) Well I use both in my panels. But I prefer when I can easily read the code.
-
5. Re: Search if a layersets with a specific name exist and execute a function if it is the case
c.pfaffenbichler Oct 15, 2014 8:01 AM (in response to Sebastien Piconnier)This would check for a LayerSet if a name with DOM code – so it’s fairly slow.
var check = checkForLayersetNamed(app.activeDocument, false, "thisName");
alert (check);
////// function collect all layers //////
function checkForLayersetNamed (theParent, theCheck, theName) {
/* if (!allLayers) {var allLayers = new Array}
else {};*/
for (var m = theParent.layers.length - 1; m >= 0;m--) {
var theLayer = theParent.layers[m];
// apply the function to layersets;
if (theLayer.typename == "ArtLayer") {
// allLayers.push(theLayer)
}
else {
if (theLayer.name == theName) {theCheck = true};
theCheck = (checkForLayersetNamed(theLayer, theCheck, theName))
// allLayers.push(theLayer);
}
};
return theCheck
};
Below is AM code Paul Riggott posted some time ago in connection with linking Layer Masks.
Re: Automatically re-link layer masks
You could add a check for whether the Layer is a LayerSet, but if the name is the sole distinguishing feature this might work as a basis for your operations.
app.bringToFront();
main();
function main(){
if(!documents.length) return;
linkLayers();
}
function linkLayers(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
var Names=[];
try{
activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
for(i;i<count;i++){
if(i == 0) continue;
ref = new ActionReference();
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID( 'Nm ' ));
var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
if(layerName.match(/^<\/Layer group/) ) continue;
/* you could insert your operations in an if clause here */
}
};
-
6. Re: Search if a layersets with a specific name exist and execute a function if it is the case
Sebastien Piconnier Oct 15, 2014 8:47 AM (in response to c.pfaffenbichler)Thank You.
And if i want to merge this layer group how I insert it on you example dom code?
-
7. Re: Search if a layersets with a specific name exist and execute a function if it is the case
c.pfaffenbichler Oct 16, 2014 12:11 AM (in response to Sebastien Piconnier)Well, that is something quite different from what you asked in the original post.
But you can insert whatever you like in the if-clause and merge() is a method of LayerSets anyway.
if (theLayer.name == theName) {theCheck = true};
-
8. Re: Search if a layersets with a specific name exist and execute a function if it is the case
Sebastien Piconnier Oct 16, 2014 4:43 AM (in response to c.pfaffenbichler)Ok thank you very much for your help , time and effort

