Hi All, Im very new with UXP.
This whole async, await, executeAsModal are still hard for me to grasp. The syntax as well.
What I want to do is to automatically select all layers in the activeDocument (doesnt matter if they’re visible or not) then nest them all in one smart object.
The smart object part is something I can copy from alchemist.
But the selecting all part is what i cant figure out. In alchemist, the listener records the name/id of the layer you selected. Im not sure how to replace it with a variable.
In the old scripting menthod, this is something I can easily do. Totally have no idea how to do it in UXP.
Any help would be greatly appreciated. Thanks!
Never mind, after sometime, finally came up with something that works:
async function selectAllLayers(){
function actionCommands() {
const app = require(“photoshop”).app;
const layers = app.activeDocument.layers;
for (i = 0; i < layers.length; i++) {
let layer = layers[i];
if (!layer.selected) {
layer.selected = true;
}
}
}
await require(‘photoshop’).core.executeAsModal(actionCommands, {“commandName”: “select all layers”});
}
Welcome meatloaf_18
Since you’re just starting out, my advice is to use some methods to use UXP,
to get started you can use the actions panel,
select the action you want to convert, go to the 3 lines on the right and select copy as javascript and paste it into the document.
Second option
go to the plugin menu at the bottom and you will find devetolement
and select
record action notification
or
record action command.
Another option, and use alchemist
a powerful tool created by Jarda, a person of great intelligence and availability.
anyway this should do what you ask.
SELECT_LAYER()
async function Layer_Unic() {
let result;
let psAction = require("photoshop").action;
let command = [
{"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"back"}],"layerID":[1],"makeVisible":false},
{"_obj":"set","_target":[{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"}],"to":{"_obj":"layer","name":"Sfondo"}},
{"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"front"}],"layerID":[5],"makeVisible":false},
{"_obj":"select","_target":[{"_name":"Sfondo","_ref":"layer"}],"layerID":[1,16,17,18,19,20,21],"makeVisible":false,"selectionModifier":{"_enum":"selectionModifierType","_value":"addToSelectionContinuous"}},
{"_obj":"newPlacedLayer"}
];
result = await psAction.batchPlay(command, {});
}
async function SELECT_LAYER() {
await require("photoshop").core.executeAsModal(Layer_Unic, {"commandName": "Action Commands"});
}