Skip to content

Instantly share code, notes, and snippets.

@mhulse
Last active June 11, 2016 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhulse/eb0ffb2bd365975632d2 to your computer and use it in GitHub Desktop.
Save mhulse/eb0ffb2bd365975632d2 to your computer and use it in GitHub Desktop.
Adobe Illustrator JSX script demo using BridgeTalk to communicate with palette window.
#target illustrator
#targetengine main
var NS = 'FOO';
var TITLE = 'Test';
var doc = app.activeDocument; // Just to show that this can be here ...
// BridgeTalk message:
var btm = function(fun_name, parameters) {
var ref_parameters;
var bt;
var msg;
// Test type of parameters:
if (parameters != undefined) {
if ((typeof parameters == 'string') || (parameters instanceof String)) {
ref_parameters = ((parameters != undefined) ? ('"' + parameters + '"') : '');
} else {
ref_parameters = parameters;
}
} else {
ref_parameters = '';
}
// Make BridgeTalk message:
bt = new BridgeTalk;
bt.target = 'illustrator';
msg = (eval(fun_name) + '\r ' + fun_name + '(' + ref_parameters + ');');
bt.body = msg;
bt.send();
};
// Get function name (use target function name without brackets):
var getFunctionName = function(fun_name) {
var ret = fun_name.toString();
ret = ret.substr('function '.length);
ret = ret.substr(0, ret.indexOf('('));
return ret;
};
// Your function:
function myFunction(parameter) {
$.writeln(parameter);
$.writeln(doc.layers.length); // ... and called from here.
}
// GUI constructor:
NS = new Function('this.windowRef = null;');
// GUI window:
NS.prototype.run = function() {
var win;
var myListbox;
var myButton;
// Main window:
win = new Window('palette', TITLE, undefined, { resizeable: true });
win.orientation = 'column';
win.alignChildren = ['fill', 'fill'];
// If need to update the window, like `onClick`, use: `win.layout.layout(true);`.
win.onResizing = function() { this.layout.resize(); };
win.onShow = function() { win.layout.resize(); }
// Listbox:
myListbox = win.add('listbox', undefined, ['Text', 2], {
numberOfColumns: 1,
showHeaders: true,
columnTitles: ['Values']
});
// Button:
myButton = win.add('button', undefined, 'What Value?');
myButton.onClick = function() {
btMsg(getFunctionName(myFunction), myListbox.selection.text);
}
// Close button:
win.btnQuit = win.add('button', undefined, 'Close');
win.btnQuit.onClick = function() { win.close(); }
// Window Lauch Properties:
win.center();
win.show();
}
new NS().run();
$.writeln('finished');
@mhulse
Copy link
Author

mhulse commented Nov 24, 2015

Original code found here: More agile way to use BridgeTalk functions

@mhulse
Copy link
Author

mhulse commented May 14, 2016

@mhulse
Copy link
Author

mhulse commented Jun 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment