Copy link to clipboard
Copied
I wish to go through a large batch of files and hide all groups with the prefix "10_" and then save them off as a png.
I was going to attempt this through Actions (using "Find" in the layers tab or in the Select Menu), but it won't record that.
So I think it will need to be a script. I can find scripts where folks have hidden layers by name, but I hope to do this by name prefix.
I'm using Windows, so I'm thinking of using JavaScript (JSX).
Try the following, change the prefix if needed in the function call on the last statement
function getDesc(className, property, index)
{
var r = new ActionReference(), p = stringIDToTypeID(property)
r.putProperty(stringIDToTypeID('property'), p)
if(index != undefined)
r.putIndex(stringIDToTypeID(className),index)
else
r.putEnumerated(stringIDToTypeID(className), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'))
var a = executeActionGet(r)
return a
}
function findAn
...
Hi folks, sorry I thought it would let me know if people replied, haha.
I did figure it out, and this looks the closest to how I approached it here, but I was a bit more... hacky.
if(app.documents.length>0){
var docRef = app.activeDocument;
var myLyr = docRef.layerSets;
for (var i = 0; i < myLyr.length; i++) {
if(myLyr[i].name.indexOf("10_")!=-1){
var myGrp = myLyr[i].artLayers;
for (var ii = (myGrp.length); ii > 0; ii--) {
myGrp[ii-1].visible = false;
}
var
...
Copy link to clipboard
Copied
Yes an Action can not do something like that and an document can have many layer groups with the prefix 10_ and they can be nested in other layer groups with or without a 10_ prefix. Files can be layer or not layered they may or may not layer groups or any layer groups with a 10_ prefix. The script need to be able to process any document that you may have in your batch file list. You will need to code a recursive process to process all layer groups a document may have. As far as action go I do not think that you could even record find or selecting a layer group with a 10_ prefix and if you could it would not be a conditional step that you could do something if not found. You would definitely need to use Photoshop scripting. As for your layers and layer group. If you create the document you may know how they are structured and you may be able to process some particular document structure and know where in the structure a layer group with a 10_ prefix may be. If other's create the document where you have no idea how the document may be structured you most likely can not use get by name for I do not think wildcarding is possible and layer and layer groups name need not be unique there can be duplicate names in a document yow will likely need to process the whole document's structure.
Copy link to clipboard
Copied
If you have sample code then please post it, it is much easier to revise existing code than reinvent the wheel from scratch.
Copy link to clipboard
Copied
Try the following, change the prefix if needed in the function call on the last statement
function getDesc(className, property, index)
{
var r = new ActionReference(), p = stringIDToTypeID(property)
r.putProperty(stringIDToTypeID('property'), p)
if(index != undefined)
r.putIndex(stringIDToTypeID(className),index)
else
r.putEnumerated(stringIDToTypeID(className), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'))
var a = executeActionGet(r)
return a
}
function findAndHideGrp(prefix)
{
var layerCount = getDesc("document", "numberOfLayers").getInteger(stringIDToTypeID("numberOfLayers"))
var i = getDesc("document", "hasBackgroundLayer").getBoolean(stringIDToTypeID("hasBackgroundLayer")) ? 0 : 1
for(; i <= layerCount; i++)
{
var retval = typeIDToStringID(getDesc("layer", "layerSection", i).getEnumerationValue(stringIDToTypeID("layerSection")))
if(retval == 'layerSectionStart')
{
var r = new ActionReference()
r.putIndex(stringIDToTypeID('layer'), i)
var layer = executeActionGet(r)
var layerName = layer.getString(stringIDToTypeID("name"))
if(new RegExp("^" + prefix).test(layerName))
{
var ad = new ActionDescriptor();
var al = new ActionList();
var ar = new ActionReference();
ar.putIndex(stringIDToTypeID("layer"), i)
al.putReference(ar);
ad.putList( stringIDToTypeID( "null" ), al );
executeAction( stringIDToTypeID("hide"), ad, DialogModes.NO);
}
}
}
}
findAndHideGrp("10_")
-Manan
Copy link to clipboard
Copied
Hi folks, sorry I thought it would let me know if people replied, haha.
I did figure it out, and this looks the closest to how I approached it here, but I was a bit more... hacky.
if(app.documents.length>0){
var docRef = app.activeDocument;
var myLyr = docRef.layerSets;
for (var i = 0; i < myLyr.length; i++) {
if(myLyr[i].name.indexOf("10_")!=-1){
var myGrp = myLyr[i].artLayers;
for (var ii = (myGrp.length); ii > 0; ii--) {
myGrp[ii-1].visible = false;
}
var mySubGrp = myLyr[i].layerSets;
for (var ii = (mySubGrp.length); ii > 0; ii--) {
mySubGrp[ii-1].visible = false;
}
}
}
}
If you're wondering why I hid the layers and groups INSIDE the groups instead of the groups themselves I have a reason, but I don't remember it exactly. It was more reliable this way though. I originally deleted the layers/groups in my for loop (because I was gonna be saving off flattened jpgs anyway) but that ran into issues with locked layers. But by this point I understood what I was doing a lot more, so I hid them instead.
Oh also the reason I count down for my for loops is because when I was deleting them it wasn't tracking how it was originally sorted so it would miss layers, so you can count up with it hiding them instead.