Photoshop move layer along y-axis

非 Y 不嫁゛ 提交于 2021-02-04 21:45:22

问题


I'm working on a script that will move a layer, right, left, up, or down. This depends upon which edge of the layer is inside the canvas.

I've managed to get the layer moving left and right (x-axis) using bounds[0] and bounds[2].

But when I try to get it to move up or down, it still moves left/right. Is it the bounds number I've got wrong?

var Y1 = bounds[3].as('px');
var Height = app.activeDocument.height.as('px');

//move down
if (Y1 < Height) {
activeDocument.activeLayer.translate(Height-Y1); 
}

回答1:


The first thing you probably want to do in a situation like this is to check the documentation. For .translate() we can find the following:

so to move horizontally we would use deltaX and to move vertically deltaY, in your code you're giving to .translate() only deltaX, so as expected your layer is being moved horizontally. To fix this pass 0 as a first argument and your Height-Y1 as a second one:

activeDocument.activeLayer.translate(0, Height - Y1);


来源:https://stackoverflow.com/questions/59031370/photoshop-move-layer-along-y-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!