簡體   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