Hi folks,
I got the errors many times when I tried to create a file psd from an active document:
{"message":"NAPI API failure: Invalid argument"}
The special thing I did is combine 2 actions in one command (open file & create file psd)
The sourceFileToken and fileToken is the results from action generated token code (localFileSystem.createSessionToken)
Here it’s my code to create a new file psd from an active document:
[
{
_obj: "open",
null: {
_path: sourceFileToken,
_kind: "local"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "save",
as: {
_obj: "photoshop35Format",
},
in: {
_path: fileToken,
_kind: "local"
},
copy: true,
lowerCase: true,
_options: {
dialogOptions: "dontDisplay"
}
}
];
Did someone get in the same trouble? I had researched the document but had no clue
Maher
May 4, 2023, 5:40am
2
does each command work separately?
maybe test with synchronous execution set to true
also why not use simple open and save methods?
Yeah, I had tried to separate 2 actions (open file & save file as psd), it will work perfectly.
I think the reason did not come from that, maybe the security or block script run of the antivirus has stopped the API.
Maher
May 4, 2023, 1:05pm
4
I tried reproducing the error but I couldn’t:
I created the following test code and it works as expected:
const {
core: { executeAsModal },
action: { batchPlay },
} = require("photoshop");
const {
storage: { localFileSystem: lfs },
} = require('uxp');
async function test() {
let sourceFile = await lfs.getEntryWithUrl("D:\\file.psd")
let sourceFileToken = await lfs.createSessionToken(sourceFile);
let dirEntry = await lfs.getEntryWithUrl("D:\\")
let targetFile = await dirEntry.createFile("file2.psd")
let fileToken = await lfs.createSessionToken(targetFile);
let commands = [
{
_obj: "open",
null: {
_path: sourceFileToken,
_kind: "local"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "save",
as: {
_obj: "photoshop35Format",
},
in: {
_path: fileToken,
_kind: "local"
},
copy: true,
lowerCase: true,
_options: {
dialogOptions: "dontDisplay"
}
}
];
executeAsModal(async ()=> {
await batchPlay(commands, {})
})
}
could you please test it on your side, paying attention to file names and paths, and report back.
also make sure you have the correct permissions in your manifest
Yes, I will try it and notify you later. Thank you so much!