![](/img/trans.png)
[英]Photoshop scripting - how to create text layer in one history state
[英]Photoshop scripting: changing text of a text layer
因为我没有足够的时间来学习有关PS-Scripting的所有知识,所以我想知道,如果你能帮助我的话。
这很简单。 我想要一个JS-Script,它可以改变顶层的文本。 例如:Text为“#005”,脚本应加1,因此显示“#006”。 之后,它应该使用当前编号(006)导出(另存为Web和设备,透明度为@ 1280x720)文件。
这是一个层的屏幕( omg在德国!11 ): imageshack.us/photo/my-images/706/helpal.png
为downvoters编辑:
请为了帮助社区并避免误导/错误信息(如果我在这种情况下做出任何信息),从而使StackOverflow成为一个更好的地方,请在下面添加一条评论,说明是什么让您认为代码或方向值得投降。 如果有任何错误或误导,我将再学习一件事,我会感激不尽。
首先,您需要创建一个动作。
.jsx
扩展名保存以下代码。 File > Scripts > Browse
然后选择该脚本 然后你需要自动完成所有这些。 没有打开的文件 ,
File > Automate > Batch
Suppress File Open Options Dialogs
并Suppress Color Profile Warnings
。 由于在录制时您未包括打开文件的操作, 因此请取消选择第一个选项“ Override Action Open Commands
。 否则它将不会打开任何文件,但仍然会尝试执行文件的脚本*编号。 如有必要,请选择第二个选项Include All Subfolders
。 使用CS6的人的另一点: Adobe Developer Connection表明......
Adobe Photoshop CS6不安装Scripting文件夹。 请使用以下链接手动安装Samples,Documentation和Scripting Listener插件。
function getTextLayer(target) {
// this basically loops all the layers to find the
// upmost text layer with the content #nn... and returns it
if (target == null) return false;
var layers = target.layers,
layerLen = layers.length;
for (var i = 0; i < layerLen; i++) {
var layer = layers[i],
isLayerSet = layer.typename == 'LayerSet',
isValid = layer.kind == LayerKind.TEXT &&
/^\s*#\d+\s*$/.test(layer.textItem.contents);
// we're allowing spaces around the text just in case
if (!isLayerSet && !isValid) continue;
if (isLayerSet) {
var found = getTextLayer(layer);
if (found) return found;
} else return layer;
}
return false;
}
var doc;
try {
doc = app.activeDocument;
// the front document
} catch(e) {}
var txtLayer = getTextLayer(doc);
// obviously, the text layer if found
if (txtLayer) {
var num = txtLayer.textItem.contents.match(/\d+/)[0],
// find the numeric part
len = num.length,
// find the length of the numeric part
num = (parseInt(num,10)+1).toString();
// add 1 to that number
while (num.length < len) num = '0' + num;
// and adjust length if necessary so that e.g.
// 032 will not become 33 but it will become 033
txtLayer.textItem.contents = '#' + num;
// update layer content
var ext = '.png',
dir = decodeURI(doc.path) + '/png24',
// to use the same directory where the layered file exists
// just keep it as decodeURI(doc.path)
// I added a folder here, which actually does not exist
// but it doesn't matter because I'm making it create it
// below in case there's no such directory.
fileName = dir + '/' + num + ext,
i = 0;
if (!Folder(dir).exists) Folder(dir).create();
// create the directory if it doesn't exist
while (File(fileName).exists)
fileName = dir + '/' + num + '-' + (++i) + ext;
// if file with that name exists, add -n to the end of the name
var file = new File(fileName),
opts = new ExportOptionsSaveForWeb();
with (opts) {
format = SaveDocumentType.PNG;
PNG8 = false;
}
doc.exportDocument(file, ExportType.SAVEFORWEB, opts);
// save for web
}
if (doc) {
doc.close(SaveOptions.DONOTSAVECHANGES);
// close the original layered document without saving
}
doc = null;
// remove reference
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.