Copy link to clipboard
Copied
I am running a separate node server as described in this tutorial to create a plugin with generator-core. http://tomkrcha.com/?p=3896
I am in a situation where I need to send a lot of JS to photoshop via generator.evaluateJSXString(). But this can get out of hand easily as you can only send a string. So for any complicated functionality it becomes difficult to maintain. Is it possible define a bunch of functions in a extend script file and then call those functions from the node app?
So i could send:
generator.evaluateJSXString('doSomeStuff()');
And in a script somewhere (I don't know where this script should go)
I have that function defined which can do some stuff
function doSomeStuff(){
for(var i = 0; i < 10; i++){
doc.artLayers.add();
}
}
Where would the Extend Script File go in this instance? OR is there a better way to achieve this sort of thing.
1 Correct answer
Just a mixed collection of thoughts:
- Yes, you can package scripts as .jsx files (also jsxbin if you don't want to share source) and run them with generator.evaluateJSXFile(path), which will then run same as in ESTK. This has a couple of limitations
- It's just one file that executes, i.e. no "call this function". I've managed this by splitting my Javascript to libraries and plugins (=that one function). Then I use Gulp to concatenate needed libraries to every plugin to create 20+ jsx scripts that I
Explore related tutorials & articles
Copy link to clipboard
Copied
I'm moving this post to the scripting forum.
Copy link to clipboard
Copied
Just a mixed collection of thoughts:
- Yes, you can package scripts as .jsx files (also jsxbin if you don't want to share source) and run them with generator.evaluateJSXFile(path), which will then run same as in ESTK. This has a couple of limitations
- It's just one file that executes, i.e. no "call this function". I've managed this by splitting my Javascript to libraries and plugins (=that one function). Then I use Gulp to concatenate needed libraries to every plugin to create 20+ jsx scripts that I call from both Node & Photoshop panels
- There is no parameter passing, but it can be be overcome by having a separate script (that you run as a string) store parameter (or fetch result) to Photoshop as a custom persistent action descriptor
- It's just one file that executes, i.e. no "call this function". I've managed this by splitting my Javascript to libraries and plugins (=that one function). Then I use Gulp to concatenate needed libraries to every plugin to create 20+ jsx scripts that I call from both Node & Photoshop panels
- The plugin folder where your main.js is can be accessed by Node.js variable "__dirname"
- Depending on how you use paths, you might have to consider Windows "\" vs. Mac "/"
- Another good way of communication between Photoshop panels and Node is to setup a webserver in Node and use Ajax/jQuery in Photoshop panel. You can do ~500ms update polling and get pretty real time panel reactions.
Copy link to clipboard
Copied
Thanks for this, thats cleared up everything! It's pretty annoying that you cant pass params to a function, do you think this is a limitation due to generator-core being such a new tech, or a purpose made design decision?
Copy link to clipboard
Copied
Well, it's relatively complex. Even though "it's all javascript", you really three totally separate things with "ESTK/Photoshop DOM", Photoshop panels/Chrome and Node.js running that javascript. So it's not just calling a function but more "let me send a message to that program and ask them to call a function". Also since the browser roots, there is no "inter-script-communications", so no standard way of sending a script data.

