Copy link to clipboard
Copied
I use this code to select the above/under the currently selected layer, but this script skips the hidden layer.
How do i modify the script to include the hidden one?
async function selectLayer(executionControl, direction) {
await batchPlay(
[
{
_obj: "select",
_target: [
{
_ref: "layer",
_enum: "ordinal",
_value: direction === Directions.up ? "forwardEnum" : "backwardEnum",
},
],
makeVisible: false,
_options: {
dialogOptions: "dontDisplay",
},
},
],
{},
);
}
Copy link to clipboard
Copied
I don't know if this is possible with UXP DOM code, however, with UXP batchPlay, it should, in theory, be the same as when using an action:
Perhaps you could tidy this up (I don't know UXP):
// Select Forward Invisible Layer.psjs
async function selectForwardInvisibleLayer() {
let result;
let psAction = require("photoshop").action;
let command = [
// Show current layer
{ "_obj": "show", "null": [{ "_enum": "ordinal", "_ref": "layer", "_value": "targetEnum" }], "toggleOptionsPalette": true },
// Select forward layer
{ "_obj": "select", "_target": [{ "_enum": "ordinal", "_ref": "layer", "_value": "forwardEnum" }], "makeVisible": false },
// Show current layer
{ "_obj": "show", "null": [{ "_enum": "ordinal", "_ref": "layer", "_value": "targetEnum" }], "toggleOptionsPalette": true }
];
result = await psAction.batchPlay(command, {});
}
async function runModalFunction() {
await require("photoshop").core.executeAsModal(selectForwardInvisibleLayer, { "commandName": "Action Commands" });
}
await runModalFunction();
// Select Backward Invisible Layer.psjs
async function selectBackwardInvisibleLayer() {
let result;
let psAction = require("photoshop").action;
let command = [
// Show current layer
{ "_obj": "show", "null": [{ "_enum": "ordinal", "_ref": "layer", "_value": "targetEnum" }], "toggleOptionsPalette": true },
// Select backward layer
{ "_obj": "select", "_target": [{ "_enum": "ordinal", "_ref": "layer", "_value": "backwardEnum" }], "makeVisible": false },
// Show current layer
{ "_obj": "show", "null": [{ "_enum": "ordinal", "_ref": "layer", "_value": "targetEnum" }], "toggleOptionsPalette": true }
];
result = await psAction.batchPlay(command, {});
}
async function runModalFunction() {
await require("photoshop").core.executeAsModal(selectBackwardInvisibleLayer, { "commandName": "Action Commands" });
}
await runModalFunction();
I'm sure that there are better ways!
Copy link to clipboard
Copied
Thank you for the response, but unfortunately, this script doesn't work properly if I have group or nested layers.
Copy link to clipboard
Copied
I tested with root/top-level artLayers and layerSets but as it's based on the standard keyboard shortcut for traversing layers it has limitations.
Please post a screenshot of the layers panel or attach a sample layered PSD.
Sadly UXP hasn't gained much traction in the scripting community outside of plugin development.
Good luck!
Copy link to clipboard
Copied
Sure,
Copy link to clipboard
Copied
You could try to re-create the following ExtendScript in UXP, easier said than done I'm sure!
Copy link to clipboard
Copied