Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

More agile way to use BridgeTalk functions

$
0
0

I have used BridgeTalk now in my couple scripts. I found this way to more agile way to use functions with BridgeTalk. Just want to share this and get comments if there is more better way to do this.

 

So, I just get function name and evaluate function itself to BT message body. In this way I just need to call BT message only with one line and make it more dynamic.

 

// BridgeTalk Message
function btMsg ( fun_name, parameters ) {       var ref_parameters;       // 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    var bt = new BridgeTalk;    bt.target = "illustrator";    var msg = eval(fun_name) + '\r ' + fun_name + '(' + ref_parameters + ');';    bt.body = msg;    bt.send();
}

// GET: Function name. (Use target function name without brackets)
function getFunctionName ( 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);
}


// GUI Constructor
function GUI() { this.windowRef = null; } 

// GUI Window
GUI.prototype.run = function() 
{       // WINDOW: Main Window    var win = new Window( "palette", script_name, undefined );    win.orientation = "column";    win.alignChildren = ["fill", "fill"];       // LISTBOX    myListbox = win.add ("listbox", undefined, ['Text', 2],         {             numberOfColumns: 1,             showHeaders: true,            columnTitles: ['Values']        });     // BUTTON: Hello    var myButton = win.add("button", undefined, "What Value?");    myButton.onClick = function() {        btMsg ( getFunctionName(myFunction), myListbox.selection.text );    }    // BUTTON: Close button    win.btnQuit = win.add("button", undefined, "Close");    win.btnQuit.onClick = function() { win.close(); }     // Window Lauch Properties    win.center();    win.show();
}

new GUI().run();

Viewing all articles
Browse latest Browse all 12845

Trending Articles