简体   繁体   English

Photoshop Extendscript - 文件被锁定 - 无法保存

[英]Photoshop Extendscript - File is locked - Cant save

I can't save my file with javascript. The error when trying to save the file via my script is:我无法使用 javascript 保存我的文件。尝试通过我的脚本保存文件时出现的错误是:

Could not save a copy as "..." because the file is locked, you do not have necessary permissions, or another program is using the file.无法将副本另存为“...”,因为文件已锁定,您没有必要的权限,或者另一个程序正在使用该文件。 Use the "properties" command in the Windows Explorer to unlock the file.使用 Windows 资源管理器中的“属性”命令解锁文件。

If I press ok, my script tells me "User abort".如果我按确定,我的脚本会告诉我“用户中止”。

I already successfully wrote a few.jsx with the extendscript toolkit to automate photoshop but this is the first time reading.psd paths from a csv list and opening them in photoshop.我已经使用 extendscript 工具包成功编写了一些 .jsx 来自动化 photoshop,但这是第一次从 csv 列表中读取 .psd 路径并在 photoshop 中打开它们。

I think the problem is because "var docRef = app.activeDocument;"我认为问题是因为“var docRef = app.activeDocument;” is created in my savePng function while still in the loop reading my.csv在我的 savePng function 中创建,同时仍在循环中读取 my.csv

Here is a part of my code where I am looping all my photoshop files and trying to save them as.png这是我的代码的一部分,我循环所有的 photoshop 文件并尝试将它们另存为 .png

I do a few functions here to process my automation.我在这里执行一些功能来处理我的自动化。

for (var i = 0; i <= lineslength - 2; i++){
    if(typeof lines[i] !== "undefined")
    {
        app.open(new File(lines[i]));
        var docname = app.activeDocument;
        var filenamelong = docname.name
        var filename = filenamelong.substring(4, filenamelong.length - 4);
        clickonlayer()
        createlayer()
        isolate()
        maskinput("image_mask")
        try {
            maskadd("image2_mask")
            maskadd("image3_mask")
            maskadd("image4_mask")
        }
        catch(error){
        }
        setcolor()
        deselect()
        savePng(filename)
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        filenew.writeln(lines[i] + "        EXPORTED")
    } 
}

Here is my savePng function:这是我的 savePng function:

function savePng(psdname) {
var docRef = app.activeDocument;
var exppath = "C:/Users/Jeremy/Documents/export";
var filepath = psdname + '.png'
var file = new File(filepath);
var opts = new PNGSaveOptions();
docRef.saveAs(file, opts, true);
}

Usually in my photoshop scripts I open a file and create the app.activeDocument variable but this time it needs to be created after the file will be opened via the script.通常在我的 photoshop 脚本中,我打开一个文件并创建 app.activeDocument 变量,但这次需要在通过脚本打开文件后创建它。

I appreciate any help.我感谢任何帮助。

var filepath = psdname + '.png'

I belive there should be我相信应该有

var filepath = exppath + "/" + psdname + '.png'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM