这个问题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脚本参考,我不明白怎么可能先创建一个层,然后再添加它。
我仍然在问,因为我可能遗漏了什么,或者有官方的方法可以做到这一点,但由于某种原因没有出现在官方文档中。
发布于 2020-12-17 17:10:19
迟到总比不到好,但这是可能的。您只需使用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; // NORMALhttps://stackoverflow.com/questions/34801453
复制相似问题