繁体   English   中英

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

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

这个问题Photoshop Script to create text in a bitmap image in Photoshop已经回答了如何在 photoshop 中创建文本层,但是作为历史选项卡的结果,您可以看到 8-10 历史状态变化。 有没有办法做同样的工作,但只改变历史一次?

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

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

函数 add() 创建新层,添加它然后返回它。 因此,根据 Javascript Scripting Reference,我看不出如何先创建一个层然后添加它。

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

迟到总比不到好,但是有可能。 您只需要使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM