我试图将activeDocument
保存为.psd,但却返回此错误
错误:发生一般Photoshop错误。此版本的Photoshop可能无法使用此功能。
#target photoshop
var fileRef = new File(app.path.toString() + "/Samples/template.psd");
var docRef = open(fileRef);
//target text layer
var layerRef = app.activeDocument.layers.getByName("Text");
//user input
var newText = prompt("Editing " + layerRef.name, "enter new text: ");
//change contents
layerRef.textItem.contents = newText;
//save
var savePath = "/Samples/" + newText + ".psd";
var saveFile = new File(savePath);
var saveOptions = new PhotoshopSaveOptions();
saveOptions.alphaChannels = false;
saveOptions.annotations = false;
saveOptions.embedColorProfile = true;
saveOptions.layers = true;
saveOptions.spotColors = false;
app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
app.activeDocument.close();
我想要做的基本上是,一遍又一遍地复制模板文件,只替换文本层的内容,然后将其保存在文本层中我替换的字符串下。
非常感谢任何提示或帮助。
答案 0 :(得分:0)
我通过解决方法解决了我的问题。我将脚本和模板文件移动到Photoshop目录中,并将app.path.toString()
添加到saveFile
输出变量中。因此,似乎需要在保存之前将路径转换为字符串。
到目前为止,我不确定如何在Photoshop目录之外工作,但对我而言这很有效,所以我很高兴。这是一个相当粗糙但我可以接受的建议。因此,如果有人遇到类似的问题,他们可以使用它作为参考。
#target photoshop
var loop = true;
var filePath = "/Samples/template.psd";
while(loop) {
openTemplate(filePath);
var layerRef = app.activeDocument.layers.getByName("Text"); //target text layer
var newText = prompt("Editing " + layerRef.name, "enter new text: "); //user input
if(newText == "stop") { //stop loop by entering 'stop'
loop = false;
}
layerRef.textItem.contents = newText;
var savePath = app.path.toString() + "/Samples/" + newText + ".psd";
var saveFile = new File(savePath);
savePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function openTemplate(filePath) { //open template.psd
var fileRef = new File(app.path.toString() + filePath);
var docRef = open(fileRef);
}
function savePSD(saveFile) { //saveas newText.psd
var saveOptions = new PhotoshopSaveOptions();
saveOptions.alphaChannels = false;
saveOptions.annotations = false;
saveOptions.embedColorProfile = true;
saveOptions.layers = true;
saveOptions.spotColors = false;
app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
}
答案 1 :(得分:0)
我怀疑原始尝试的问题在于您没有指定完整路径。我总是提供一个完整的路径 - 即使它只是一个临时的位置,如' /c/temp/myfile.psd'。