开发者

exportDocument() 'destination folder does not exist' error

I'm trying to make a script in photoshop that will modify some layers and than export them as a PNG image. I've copied the following code from another place:

function SavePNG(saveFile){
    var pngOpts = new ExportOptionsSave开发者_开发百科ForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(saveFile,ExportType.SAVEFORWEB,pngOpts);
}

The function export the active document of photoshop to the file specified by the saveFile parameter.

It's working fine with simple paths like "C:\images\result.png" but when trying with different paths like "~/Desktop/" or paths with some special characters the file isn't exported, and a "destination folder does not exist" error message appears.

Any idea how can I solve it?


Well, I'm not sure why this is occur but you could try the following modification:

function SavePNG(saveFile){
    var tmpFile = "./tmp.png";
    tmpFile = new File(tmpFile);
    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(tmpFile,ExportType.SAVEFORWEB,pngOpts); 
    tmpFile.rename (saveFile);
    tmpFile.changePath(saveFile);
}

it'll export the file into a temporary file and then rename & move it to the requested path, should solve the path problem.


exportDocument expects a full file name, not a folder path.

This works:

activeDocument.exportDocument(new File("~/foo/foo.png"), ExportType.SAVEFORWEB, pngOpts);

This doesn't work and gives the 'destination folder does not exist' error message:

activeDocument.exportDocument(new File("~/foo/"), ExportType.SAVEFORWEB, pngOpts);


For people having this error and not using photoshop-script.

The error might be unbound to the destination folder, but occurs because the folder, which was used for the export step, is deleted. So either

  • recreate the folder, which was used during recording, or
  • recreate the export step
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜