gpt4 book ai didi

javascript - Photoshop 沿 y 轴移动图层

转载 作者:行者123 更新时间:2023-12-01 00:25:43 26 4
gpt4 key购买 nike

我正在编写一个脚本,该脚本将向右、向左、向上或向下移动图层。这取决于图层的哪个边缘位于 Canvas 内。

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

但是当我尝试让它向上或向下移动时,它仍然向左/向右移动。是我弄错了边界数吗?

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() 我们可以找到以下内容:

enter image description here

因此,要水平移动,我们将使用 deltaX 并垂直移动 deltaY,在您提供给 .translate() 的代码中只有deltaX,因此正如预期的那样,您的图层正在水平移动。要修复此问题,请将 0 作为第一个参数,将 Height-Y1 作为第二个参数:

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

关于javascript - Photoshop 沿 y 轴移动图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59031370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com