Copy link to clipboard
Copied
The application has two files open" Source_l.ai" and "Dest_l.ai". I want to change the active document, and the active layer, of the active document through the UI "palette", the code of which is given below.
Two Checkboxes, "CheckSourse" and "CheckDest" are responsible for changing the active document of the application, whose functionality I'm trying to configure ....
Does anyone know how to write the correct code for such a switch?
-----------------------------------------------------------------------------------------------------------------------
Copy link to clipboard
Copied
So, i've used scripts that utilize BridgeTalk(), but I've never written any of it myself.
However, my understanding is that you're essentially building a script string and then passing it to BridgeTalk's body property.
I'm not sure of the timeline of when you want to activate a certain document.. but you can of course activate a document before invoking bt.send(). Or if you need to activate a document from inside the code you're sending in bt.message, i would think it's as simple as including [document].activate() inside the bt.message. If that doesn't work.. I'd probably try to embed another instance of BridgeTalk in the bt.message code that could be called from your panel to activate the document whose name matches some input in your dialog.
BridgeTalk() wizards, let me know if i'm way off base here.. these are just semi-educated guesses.
Copy link to clipboard
Copied
you're on the right track William, the code to activate the document (or to do anything else for that matter) must be included in the body of the BT message.
it's easier to understand if we separate the UI logic from messaging logic from the Illustrator Script logic.
Open at least two documents before running
// BridgeTalk Usage - Activate Documents
// https://community.adobe.com/t5/illustrator-discussions/bridgetalk-objects-changing-the-active-document-of-an-application-through-a-palette-ui-window/td-p/13096717
#targetengine main
var win = new Window('palette', 'Select Top Object');
var radio1 = win.add ("radiobutton", undefined, "Doc 0");
var radio2 = win.add ("radiobutton", undefined, "Doc 1");
var btnClose = win.add("button", undefined, "Close");
radio1.value = true;
radio1.onClick = function () {
buildBtMsg (1);
}
radio2.onClick = function () {
buildBtMsg (1);
}
btnClose.onClick = function () {
win.close();
}
function buildBtMsg (param) {
var bt = new BridgeTalk;
bt.target = "illustrator";
var script = activateDocument + '\ractivateDocument (' + param + ');';
bt.body = script;
bt.send();
}
win.center();
win.show();
function activateDocument (idx) {
app.documents [idx].activate();
}
Copy link to clipboard
Copied
hmm...you're sending the whole script (including making the UI) in the BridgeTalk message, it doesn't work like that.
you only need to send the script that Illustrator will execute, in this case Activate a document among other stuff.
See below for a clearer set up
Copy link to clipboard
Copied
upon rethinking it.. i might have just been assuming. but i was under the impression the dialog itself was intended to be launched via a button in a palette which i believe would mean it needs to be wrapped inside the bt.message?
I guess i may have assumed that because i've heard that only the code you want executed should be sent to bt. So when i saw the whole thing wrapped in there, perhaps my brain said "ah. that means they want to trigger the whole dialog from a pallette".