Photoshop CS4脚本或动作:在单独的文本图层上写入0到100

时间:2014-03-14 23:35:35

标签: action photoshop-script photoshop-cs4

我的目标是创建101个单独的文本图层,包含0-100(即1,2,3 ... 100)我知道我可以批量更改属性但不能写入或更改包含文本。

1 个答案:

答案 0 :(得分:0)

您可以使用脚本轻松完成所需的操作(比以正确顺序重命名100个图层并为其记录操作更容易)此脚本将创建100层文本,每个图层将命名为1,2,3 ..etc和文本将是相同的。我认为是你所追求的,你的描述相当短暂。

// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = 100;
//var numOfLayers = srcDoc.layers.length; 
var numPadding = "0";
var layerNum = 1; // change this to 0 to start layers at 0
var w = Math.floor(srcDoc.width.value/2);
var h = Math.floor(srcDoc.height.value/2);


// main loop starts here
for (var i = numOfLayers -1; i >= 0  ; i--)
{

    if (layerNum < 10) numPadding = "0";
    else numPadding ="";
    createText("Arial-BoldMT", 20.0, 0,0,0, layerNum, w, h);
    var currentLayer = srcDoc.activeLayer;
    currentLayer.name = numPadding + layerNum;
    layerNum +=1;
}

// function CREATE TEXT(typeface, size, R, G, B, content, Xpos, Ypos)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, tX, tY)
{

  var artLayerRef = srcDoc.artLayers.add()
  artLayerRef.kind = LayerKind.TEXT
  textColor = new SolidColor();
  textColor.rgb.red = colR;
  textColor.rgb.green = colG;
  textColor.rgb.blue = colB;
  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.textItem.justification.CENTER
}

将其保存为numberLayers1-100.jsx,然后通过Files - &gt;从Photoshop重新保存。脚本菜单。