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
#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
}
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.
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?
Copy link to clipboard
Copied
Thank you! the script works well, much simpler and elegant solution than what I had in mind.
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
}