Copy link to clipboard
Copied
Hello All
does anyone have a script available that checks which Subgroup (or layer) in GROUP A is visible and store it's name as variable to use it later in the script?
1. Checking GROUP A which layer or group inside it is visible (will be only one at a time).
2. Storing the name of the visible group/layer as variable.
3. use this variable (together with others) as name for the exported file.
I have a script that checks if a given layer name is visible, but i would want to check a group for a visible layer or subgroup.
Thanks everyone.
Copy link to clipboard
Copied
You need to use a recursive function to search each group and subgroup. The if statement detects if the layer is a layerset and if so restarts the function to search for layers in that group.
var doc = app.activeDocument
var layersToTargetNameArray = ["Background", "Artwork", "diecut", "size", "sign of panel"];
findLayers (doc)
function findLayers(gp){
for (var i = 0, i< gp.layers.length; i++) {
var curLayer = gp.layers;
if(curLayer.typename == 'LayerSet'){findLayers (curLayer)}
else{
for (var j = 0, jl = layersToTargetNameArray.length; j < jl; j++) {
if (curLayer.name == layersToTargetNameArray
) { // --------------------------------------------
// do something if layer name found
// --------------------------------------------
curLayer.visible = false; // basic example
} else {
// --------------------------------------------
// do something else if layer name not found
// --------------------------------------------
}
}
}
}
}
Copy link to clipboard
Copied
Thank you Chuck
I checked your script and as far as i understand it it does:
It's not exactly what i'm trying to accomplish, but a good start What i try is:
My layer structures/stacks in all needed documents are:
+Front
+Print Effects
+Colors
+Red
+Blue
+Green
+Back
+Print Effects
+Colors
+Red
+Blue
+Green
So, if "red" would be visible and i saved this to variable 'color' i could save my file as:
thedoc.saveAs((new File(docPath+'/'+ color + basename + thedoc.activeLayer.name +' .jpg')),jpegOptions,true);
Does that make sense?
p.s. i'm looking to hire someone for a scripting job, in case you would be available or knew someone Thanks Chuck
Copy link to clipboard
Copied
Copy link to clipboard
Copied
JJMack, i know this website, but that's not my question
Copy link to clipboard
Copied
I'm not totally clear on what you want. My response was just to show you how to search layers in groups and subgroups. There are people that may want to do this for you, and they should PM you. Right now, I don't really have a lot of time.
Copy link to clipboard
Copied
Hello Chuck
after hundreds of script snippet tests and reading in the forum, i did not find a solution yet. Try to explain again as simple as i can
1. I have a layerset called "Colors" which is in fact nested in another layerset called "Front".
2. My script should check which layer inside "Colors" (i.e. Red, or Yellow, or Blue) is visible and store its name as a variable.
3. When the script saves the jpg, it can append the Name of the visible layer aka Color (i.e. Blue) to my filename.
Any idea how this could be done? Thank you for your Time and have a great weekend.
Daniel
Copy link to clipboard
Copied
So, i have found a script that does select all visible layers in a document. Now i'd need to edit it to select the visible layer inside the layerset named "Colors"
How could i "limit" the script to just check the "Colors" layerset for visible layers (will be just one at a time, i.e. "Yellow")?
#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
var Vis = getVisLayers();
deselectLayers();
for(var a in Vis){
selectLayerById(Number(Vis),true);
}
}
function getVisLayers(){
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;
var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
var vis = desc.getBoolean(charIDToTypeID( "Vsbl" ));
if(!isLayerSet && vis) Names.push(Id);
};
return Names;
};
function selectLayerById(ID, add) {
add = (add == undefined) ? add = false : add;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
if (add) {
desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
}
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
function deselectLayers() {
var desc01 = new ActionDescriptor();
var ref01 = new ActionReference();
ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc01.putReference( charIDToTypeID('null'), ref01 );
executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};