Skip to main content
pdog11
Participant
August 11, 2024
Question

Unexpected Double Movement of Selected Layers in UXP Script

  • August 11, 2024
  • 1 reply
  • 235 views

I have created the following UXP code. This code is intended to move the selected layers by a specified amount. When I run this code with multiple layers (Layer A, Layer B) selected, I expect that Layer A will move by (-100, -20) from its current position, and then Layer B will move by (-100, -20) from its current position. However, in reality, both Layer A and Layer B are moved by (-100, -20) twice.

In the for loop, I expected the layers to move individually, but it seems that all selected layers are being moved together in each iteration. Is this behavior normal? How can I avoid this issue?


--------------

const { app, core } = require("photoshop");

async function testplay() {
        await core.executeAsModal(async () => {
            const doc = app.activeDocument;
            const layers = doc.activeLayers;

            for (const layer of layers) {
                await layer.translate(100, 10);
            }
        }, { commandName: 'Test Translate' });
}
This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
August 12, 2024

@Davide_Barranca12040269 , please forgive the intrusion, but I am afraid the OP might need help that the ESTK-oriented regulars cannot provide. 

Do the layers need to be deselected and selected individually or …?