Copy link to clipboard
Copied
I found a script on this community that merges top level groups into individual layers. It's ALMOST perfect for what I need EXCEPT I need it to respect the original visibility of the top level Layer Group and apply that to the merged layer. Currently when run it turns the visibility of all layers to ON regardless of the original Layer Group visibility. How can this be modified? Thank you!
#target photoshop;
activeDocument.activeLayer = activeDocument.layerSets[0].layers[0];
activeDocument.activeLayer = activeDocument.activeLayer.parent;
while (app.activeDocument.layerSets.length) {
activeDocument.activeLayer = app.activeDocument.layerSets[0];
executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}
while (app.activeDocument.layerSets.length) {
var vis = app.activeDocument.layerSets[0].visible;
activeDocument.activeLayer = app.activeDocument.layerSets[0];
executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
activeDocument.activeLayer.visible = vis;
}
Copy link to clipboard
Copied
I believe that was an alteration for a different use case, here is the original from @SuperMerlin
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-merge-each-main-group-not-subgroup-in-to-a-layer/m-p/10400702#M237128
By SuperMerlin
*/
#target photoshop;
while (app.activeDocument.layerSets.length) {
activeDocument.activeLayer = app.activeDocument.layerSets[0];
executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}
Two alternative scripts here:
Copy link to clipboard
Copied
Ah ok, good to know the origin of the script. I tried that, and the two alternative scripts, but all of them have the same result: hidden layer groups get turned into visible layers. I need each merged layer to retain the visibility status of the original layer group. I don't know how to modify it to achieve this.
Copy link to clipboard
Copied
I can see that @r-bin sorted this out. As you didn't provide screenshots to illustrate I obviously didn't understand.
Copy link to clipboard
Copied
while (app.activeDocument.layerSets.length) {
var vis = app.activeDocument.layerSets[0].visible;
activeDocument.activeLayer = app.activeDocument.layerSets[0];
executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
activeDocument.activeLayer.visible = vis;
}
Copy link to clipboard
Copied
Works great, thank you!