Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

UXP Script to select the layer directly above/under the currently selected layer including hidden?

Community Beginner ,
Jul 26, 2024 Jul 26, 2024

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",
                    },
                },
            ],
            {},
        );
}

 

TOPICS
Actions and scripting
528
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 26, 2024 Jul 26, 2024

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:

 

Stephen_A_Marsh_0-1714691253869.png

 

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2024 Jul 28, 2024

Thank you for the response, but unfortunately, this script doesn't work properly if I have group or nested layers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2024 Jul 28, 2024

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2024 Jul 28, 2024

Sure, 

AndreNguyen_0-1722230240793.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2024 Jul 28, 2024

You could try to re-create the following ExtendScript in UXP, easier said than done I'm sure!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2024 Aug 07, 2024
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines