2012-09-05 38 views
3
if (app.documents.length != 0) { 
    var doc= app.activeDocument; 

    for (i = 0; i < 5; i++) { 
     var layer = doc.artLayers[0] 
     layer.textItem.contents = i; 

     var pngFile = new File("/Users/dlokshin/temp/" + i + ".png"); 
     pngSaveOptions = new PNGSaveOptions(); 
     pngSaveOptions.interlaced = false; 
     doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE); 
    } 
} 

每当我运行上面的脚本,而不是保存文件为1.png,2.png,3.png,等一个PNG它开辟了保存对话框,并提示我输入文件名并点击保存。我究竟做错了什么?保存用photoshop脚本不工作

回答

4

自动保存PNG与为Photoshop编写脚本时保存JPEG非常不同。下面的工程PNG格式:

if (app.documents.length != 0) { 
    var doc= app.activeDocument; 

    for (i = 0; i < 5; i++) { 
     var layer = doc.artLayers[0] 
     layer.textItem.contents = i; 

     var opts, file; 
     opts = new ExportOptionsSaveForWeb(); 
     opts.format = SaveDocumentType.PNG; 
     opts.PNG8 = false; 
     opts.quality = 100; 

     pngFile = new File("/Users/dlokshin/temp/speed.png"); 
     app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts); 
    } 
} 
+0

这对我很有帮助 - 尽管自从将我的实现更改为您提供的实现以来,我看到的最大差异是PNG的保存(导出)需要很长时间。我想,我必须忍受一些事情。 – djbp

0

PNGSaveOptions对我的作品保存,如果我提供的Photoshop,像这样保存路径:

var doc = app.activeDocument; 
var filePath = activeDocument.fullName.path; 
var pngFile = File(filePath + "/" + "myname.png"); 
pngSaveOptions = new PNGSaveOptions(); 
doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE); 
0

之初

app.displayDialogs = DialogModes.NO; 

只需键入此而且你不会再得到对话框。