Photoshop 脚本 - 如何在一种历史记录状态下创建文本图层

Photoshop scripting - how to create text layer in one history state

本文关键字:记录 历史 一种 状态 图层 文本 创建 脚本 Photoshop      更新时间:2023-09-26
这个问题 Photoshop 脚本在 Photoshop

中的位图图像中创建文本已经回答了如何在 Photoshop 中创建文本图层,但结果在历史记录选项卡中您可以看到 8-10 个历史记录状态更改。有没有办法做同样的工作,但只改变一次历史?

显然,问题是提到的答案首先将一个图层添加到文档中,然后对其进行 8-10 次编辑,解决方案是创建一个图层并编辑其属性,然后在准备好后将其添加到文档中。

我在 Photoshop CC 2014 Javascript 脚本参考中搜索过,它只列出了 ArtLayers 方法的 3 种方法:add()、getByName() 和 removeAll()。

函数 add() 创建新层,添加它,然后返回它。因此,根据Javascript脚本参考,我不明白如何首先创建一个层然后添加它。

仍在问,因为可能我错过了一些东西,或者有官方的方法可以做到这一点,但由于某种原因没有进入官方文档。

迟到总比没有好,但是是的,这是可能的。您只需要使用suspendHistory暂停历史记录状态

只需将您的函数作为字符串以 app.activeDocument.suspendHistory("string", "myFunction()");

据我所知,第一个参数是历史状态字符串。

如示例中,

// Switch off any dialog boxes
displayDialogs = DialogModes.ERROR; // OFF 
app.activeDocument.suspendHistory ("history state", "createText('Arial-BoldMT', 48, 0, 128, 0, 'Hello World', 100, 50)");

function createText(fface, size, colR, colG, colB, content, tX, tY)
{
  // Add a new layer in the new document
  var artLayerRef = app.activeDocument.artLayers.add()
  // Specify that the layer is a text layer
  artLayerRef.kind = LayerKind.TEXT
  //This section defines the color of the hello world text
  textColor = new SolidColor();
  textColor.rgb.red = colR;
  textColor.rgb.green = colG;
  textColor.rgb.blue = colB;
  //Get a reference to the text item so that we can add the text and format it a bit
  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = content;
  textItemRef.color = textColor;
  textItemRef.size = size
  textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
  activeDocument.activeLayer.name = "Text";
  activeDocument.activeLayer.textItem.justification = Justification.CENTER;
}

// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL