The problem with it is that, since this is a script, I must ask for the user to open a Photoshop File, that I provide along with the script. I was wondering if using UXP I could include this file with my Plugin, this way the user wouldn’t need to do it by themselves. Is this possible?
If the answer is yes, how could I open a Photoshop File using UXP?
Thank you! I’ll try to be more present in these forums, even being just a newbie when it comes to development haha…
The photoshop object supplies an open method that you can use to open a document. Since the document would be in your plugin’s folder, you can access it using getPluginFolder():
I’ve tried recreating the crash but can’t replicate it now. I was a bit frustrated with my code at the time so it could have been something completely unrelated and I didn’t notice it.
Any ideas?
Back in CEP days I used to be able to do something like: var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) to return the path, which I could send to that batchPlay script for the UXP version?
It’s a static displacement map PSD file so can live in the packaged plugin directory so I don’t have to ask for permissions of user to use/open. Read only.
Hi Kerri,
I tried this snippet and I am unable to get it to run. I’ve have zero ideas of why considering there are no errors produced. It simply ignores the app.open() request.
Diving down the forum rabbit hole I see that v23.3 it probably now needs executeAsModal() ??
If I’m correct, can you give me an idea how I would accomplish this simple task in the api 2 language?
Thanks in advance.
Heya @AnthonyK, thanks for the response. I am trying to accomplish the simplest of tasks - Open a .psd file programmatically with a UXP plugin. Trying to find the exact code to do that now we need to use executeAsModal. @kerrishotts has the code up in this thread, but that doesn’t work now in API2 and we need to use executeAsModal. All my attempts to date do not work and the await function just seems to ‘wait’ indefinitely…
To use executeAsModal you need to first import it from photoshop and then you can pass it a function as its parameter to execute that code with Photoshop in a modal state.
// Imports
const { app, core } = require("photoshop");
const fs = require("uxp").storage.localFileSystem;
// Open document helper function
async function openDocument() {
const pluginFolder = await fs.getPluginFolder();
const theTemplate = await pluginFolder.getEntry("yourFile.psd");
// The document is opened
await app.open(theTemplate);
}
// Main function - is async so that await can be used within
async function main() {
// Passing openDocument function to executeAsModal to open file
await core.executeAsModal(openDocument);
}
// Run main function from inside try/catch for error handling
try {
// Don't need to await because a) nothing to run after it and b) you can't anyway because top-level await is not allowed
main();
} catch (error) {
console.error(error);
console.trace(error);
}
EDIT: Code edited to remove error inducing return statements and incorrect imports.
Heya @Timothy_Bennett,
Thanks for your response. I replied to a response in another thread and it the same. Not even the errors are being logged to the console. My environment must not be set up or something. Is it the manifest.json I am using?
Sorry for being a newbie.
That’s getting into guesswork territory - it would be better if you push your project to GitHub and share the repo or package it up as a .ccx in the Developer Console and send it to me via private message.
I’m happy to give it a look over and see it there’s anything in your code setup that’s arwy.
Thanks Tim,
Definitely able to do that, but my code is simply the uxp-template-ps-starter (package.json) and the same manifest you get with that option. I then paste in your code and change the “yourFile.psd” to the file that I wish to open.
I assumed that this would immediately open the file upon loading the plugin?
Yup. Def no errors. The plugins seems to stop/pause/hang at every app.open call. Ive clearly got something strange going on.
When I return to the office, ill package my plugin and upload it and see if itll run on a system other than mine.