0

I'm trying to save the activeDocument as a .psd but its returning this error

ERROR: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

my script:

#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();

what I want to do is basically, duplicate a template file over and over, only replacing the contents of a text layer then saving it under the string I replace in the text layer.

any tips or help is greatly appreciated.

4

2 回答 2

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);
}
于 2015-02-15T12:12:51.663 回答
0

I suspect the problem with your original attempt is that you are not specifying a full path. I always provide a full path - even if it is just to a temporary location like '/c/temp/myfile.psd'.

于 2015-02-15T14:26:48.367 回答