.remove()不是Photoshop CC 2017 ExtendScript工具包中的函数错误

时间:2017-06-19 08:27:17

标签: javascript photoshop photoshop-script

我正在尝试修改原始PSD然后删除原始PSD并且只想保存为新的jpg。我的代码在这一行上运行良好:

activeDocument.close(SaveOptions.DONOTSAVECHANGES);	// Close Original Image

但是当我用这一行替换上面的行时:

psd.remove();	// I want to delete Original file

它给我remove() is not a function错误。

这是完整的脚本。我已经厌倦了阅读Photoshop JS Guide 2015并且谷歌这个问题,但我没有找到任何答案。

var defaultRulerUnits = preferences.rulerUnits; 
preferences.rulerUnits = Units.PIXELS;

if (documents.length >= 1){

var hres = 0;
var vres = 0;
var OldName = activeDocument.name.substring(0, activeDocument.name.indexOf('.'));
var CurrentFolder = activeDocument.path;
var psd = app.activeDocument;
hres = activeDocument.width;
vres = activeDocument.height;

activeDocument.selection.selectAll();

if (activeDocument.layers.length >1) {
	activeDocument.selection.copy(true);
}

else{
	if (activeDocument.layers.length =1) {
	activeDocument.selection.copy(false);
	}
}

psd.remove();	// I want to delete Original file
       
var newDoc = documents.add(hres, vres, 72, OldName, NewDocumentMode.RGB, DocumentFill.WHITE);

newDoc.paste();

jpgFile = new File(CurrentFolder + "/" + OldName+ ".jpg" );
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
newDoc.saveAs(jpgFile, jpgSaveOptions, true,   Extension.LOWERCASE);

}

2 个答案:

答案 0 :(得分:2)

该线程有点晚了,但是希望这对其他人有所帮助。

remove方法需要一个文件位置。您可以像这样完成删除原始文件:

var activeDoc = app.activeDocument;
var docPath = new Folder(activeDoc.path);
var psd = new File(docPath + "/" + activeDoc.name);
...
psd.remove();

编辑:我还打算提供此便捷ESTK参考文档的链接,在该文档中我了解了如何使用File对象:http://estk.aenhancers.com/3%20-%20File%20System%20Access/file-object.html?highlight=delete

答案 1 :(得分:0)

 srcDoc.activeLayer.remove();

将删除活动图层。删除文件没有.remove()方法。