-
Notifications
You must be signed in to change notification settings - Fork 0
Calling Generator Plugins from ExtendScript
Important Note: These events will only be sent to the built-in (launched by Photoshop) Generator process that communicates with Photoshop over pipes. These events will not be sent to Generator processes connected via sockets. For more on the Generator architecture, please see: https://github.com/adobe-photoshop/generator-core/wiki/Generator-Architecture
To invoke a Generator plug-in from a Photoshop ExtendScript (JSX) script (e.g. from the ExtendScript Toolkit or in an HTML5 panel), the simplest method is to trigger a Generator menu event. On the ExtendScript (Photoshop) side, this can be done with the following code:
var generatorDesc = new ActionDescriptor();
generatorDesc.putString (app.stringIDToTypeID ("name"), "my-menu-name");
// Example of additional parameter passed to the node.js code:
generatorDesc.putString (app.stringIDToTypeID ("sampleAttribute"), "moreInfo" );
var returnDesc = executeAction (app.stringIDToTypeID ("generateAssets"), generatorDesc, DialogModes.NO);
Executing this code will do the following:
- If Generator is not currently enabled, it will enable Generator and start the built-in Generator process
- Once Generator is launched, it will trigger a menu event with a menu name of
"my-menu-name"
. - It also passes an additional parameter (under the tag
sampleAttribute
) to Generator.
On the Generator side, the node.js code for handling the event looks like this:
function handleGeneratorMenuClicked(event) {
// Ignore changes to other menus
var menu = event.generatorMenuChanged;
if (!menu || menu.name !== "my-menu-name") {
return;
}
var startingMenuState = _generator.getMenuState(menu.name);
console.log("Menu event %s, starting state %s", event, startingMenuState);
// Additional parameter passed in from the ExtendScript side:
var sampleAttr = event.generatorMenuChanged.sampleAttribute;
console.log("Got a menu event to respond to, with sample attribute: " + sampleAttr);
}
// handleGeneratorMenuClicked needs to be bound to "generatorMenuChanged events" with
// self.onPhotoshopEvent("generatorMenuChanged", handleGeneratorMenuClicked)
Note the reference to event.generatorMenuChanged.sampleAttribute
to retrieve the additional attribute passed from the script.