• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to communicate between ExtendScript and Generator-core

New Here ,
Jun 23, 2015 Jun 23, 2015

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.

TOPICS
Actions and scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 23, 2015 Jun 23, 2015

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 23, 2015 Jun 23, 2015

Copy link to clipboard

Copied

I'm moving this post to the scripting forum.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 23, 2015 Jun 23, 2015

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
  • 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2015 Jun 24, 2015

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines