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

Progressively move layers PSCC 2015

Engaged ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

I am considering a script to progressively move up all selected layers by 100px.

The number of selected layers decreases by one until the of selected layer equals one.

The number of layers in the PSD file is not constant.

The layer kind is constant.

Not sure what is the simplest solution to accomplish the script behavior.

Is a for loop the correct tool for this scripting behavior?

1- select all layers

2- deselect top layer

3- move up all selected layers 100px

4- deselect top layer from selected layers group

5- move up all selected layers 100px

6- repeat step 4

5- repeat step 5

progressively-deslect-layer.jpg

TOPICS
Actions and scripting

Views

715

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 04, 2017 Feb 04, 2017

#target photoshop

app.preferences.rulerUnits = Units.PIXELS;

var doc =activeDocument

var moveAmt = -100

var moveCurrent = -100

var numLayers = doc.layers.length

for(var i=1;i<numLayers;i++){

    doc.activeLayer = doc.layers

    try{

        doc.activeLayer.translate(0,moveCurrent)

    }

    catch(e){}

    moveCurrent+=moveAmt

    }

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 04, 2017 Feb 04, 2017

Copy link to clipboard

Copied

Yes a loop would be needed. You could do it the way you described, or it might be better just to loop through each layer and move each layer by a move distance variable then increase that variable number by the amount you want for each iteration of the loop. Selecting multiple layers and deselecting them can be a bit of a pain, not to mention you're moving multiple layers numerous times, which might slow down your script.

Votes

Translate

Translate

Report

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
Engaged ,
Feb 04, 2017 Feb 04, 2017

Copy link to clipboard

Copied

Thanks for your help.

I understand what I need with the script but don't know how to ask the question in scripting terms.

The top layer in the layer stack does not move

Each loop iteration the selected layer moves up -100px * the number of remaining loop iterations.

How do I calculate the number of remaining iterations and what is the syntax to move layers?

progrssively-move-lyrs.jpg

Votes

Translate

Translate

Report

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
Engaged ,
Feb 04, 2017 Feb 04, 2017

Copy link to clipboard

Copied

LATEST

Thank you! the script works well, much simpler and elegant solution than what I had in mind.

Votes

Translate

Translate

Report

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 ,
Feb 04, 2017 Feb 04, 2017

Copy link to clipboard

Copied

#target photoshop

app.preferences.rulerUnits = Units.PIXELS;

var doc =activeDocument

var moveAmt = -100

var moveCurrent = -100

var numLayers = doc.layers.length

for(var i=1;i<numLayers;i++){

    doc.activeLayer = doc.layers

    try{

        doc.activeLayer.translate(0,moveCurrent)

    }

    catch(e){}

    moveCurrent+=moveAmt

    }

Votes

Translate

Translate

Report

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