首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Photoshop脚本-如何在一个历史状态下创建文本层

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

Stack Overflow用户
提问于 2016-01-15 07:06:05
回答 1查看 383关注 0票数 3

这个问题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脚本参考,我不明白怎么可能先创建一个层,然后再添加它。

我仍然在问,因为我可能遗漏了什么,或者有官方的方法可以做到这一点,但由于某种原因没有出现在官方文档中。

EN

回答 1

Stack Overflow用户

发布于 2020-12-17 17:10:19

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

只需以app.activeDocument.suspendHistory("string", "myFunction()");的形式将函数作为字符串传递即可

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

如示例中所示,

代码语言:javascript
复制
// 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34801453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档