Photoshop 沿 y 轴移动图层

Photoshop move layer along y-axis

我正在编写一个脚本,它将向右、向左、向上或向下移动一层。这取决于层的哪个边缘在 canvas.

我已经设法使用 bounds[0] 和 bounds[2] 使图层左右移动(x 轴)。

但是当我试图让它向上或向下移动时,它仍然移动 left/right。是我写错了边界数吗?

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

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

在这种情况下,您可能要做的第一件事就是检查 the documentation。对于 .translate() 我们可以找到以下内容:

所以要水平移动我们会使用 deltaX 并垂直移动 deltaY,在你的代码中你只给 .translate() deltaX,所以正如预期的那样您的图层正在水平移动。要将此传递 0 修复为第一个参数,将您的 Height-Y1 修复为第二个参数:

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