Copy link to clipboard
Copied
The following code will ensure that only the top layer is active (optional?) and visible and that all other top-level layers are invisible:
try {
// Ensure that the top layer is active/selected, even if no layers are currently selected
activeDocument.activeLayer.link(activeDocument.activeLayer);
// Set the top layer's visibility to off
app.activeDocument.layers[0].visible = false;
// Toggle off the visibility of all other layers except the top layer
var s2t =
...
Copy link to clipboard
Copied
Here in the following section of code, I have added an alert to pause the script so that you can screenshot the layers panel to show which layers you are talking about:
// Activate the smart object layer and open the contents
doc.activeLayer = smartObj;
// replaceContents (inputFolderPath + "/artwork" + i + ".jpg");
// Get a reference to the active document and place the corresponding image
var subDoc = openSmartObject();
var inputFilePath = inputFolderPath + "/a (" + i + ").png";
var inputImgFile = new File(inputFilePath);
placeScaleRotateFile(inputFilePath, 0, 0, 100, 100, 0)
alert("Take a screenshot of the layers panel of the open smart object")!
// Close and save the smart object contents
subDoc.close(SaveOptions.SAVECHANGES);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The following code will ensure that only the top layer is active (optional?) and visible and that all other top-level layers are invisible:
try {
// Ensure that the top layer is active/selected, even if no layers are currently selected
activeDocument.activeLayer.link(activeDocument.activeLayer);
// Set the top layer's visibility to off
app.activeDocument.layers[0].visible = false;
// Toggle off the visibility of all other layers except the top layer
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
list.putReference(reference);
descriptor.putList(s2t("null"), list);
descriptor.putBoolean(s2t("toggleOptionsPalette"), true);
executeAction(s2t("show"), descriptor, DialogModes.NO);
} catch (e) {
alert("Error!" + "\r" + e + ' ' + e.line);
}
If you are not concerned about having the top layer active/selected, you can remove the first line from the previous code or use the following:
// Make all layers invisible
for (var i = 0; i < app.activeDocument.layers.length; i++) {
app.activeDocument.layers[i].visible = false;
}
// Set the top layer's visibility to on
app.activeDocument.layers[0].visible = true;
Or:
for (var i = 0; i < app.activeDocument.layers.length; i++) {
if (app.activeDocument.layers[i] != app.activeDocument.layers[0]) {
app.activeDocument.layers[i].visible = false;
}
}
Copy link to clipboard
Copied