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

BridgeTalk objects. Changing the active document of an application through a palette UI window

Participant ,
Jul 27, 2022 Jul 27, 2022

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?

 

 

-----------------------------------------------------------------------------------------------------------------------

#target Illustrator;
#targetengine main;

app.documents.getByName("Source_l.ai").activate();
app.activeDocument.activeLayer = app.activeDocument.layers[0];
app.redraw();

function WinObject() {
    var windowResource = "palette { text: 'Devide PathItems', panelSNumObjects: Panel { orientation:'row', spacing:0, margins:10,    text: 'Goal',     Group1: Group { orientation:'row', spacing:16, margins:5,         CheckSourse: Checkbox { alignment:'center', text:'S.', value:true}, st: StaticText { text:'0', characters:3 },    },     Group2: Group { orientation:'row', spacing:16, margins:5,         CheckDest: Checkbox { alignment:'center', text:'D.', value:false }, st: StaticText { text:'0', characters:3 }, }, }, panelDevide: Panel { orientation:'row', spacing:10, margins:10,text: 'Devide', et: EditText { text:'0', characters:2, alignment:'center' }, CheckSel: Checkbox {alignment:'center', text:'Sel.', value:true ,},CheckAuto: Checkbox {alignment:'center', text:'Auto.', value:false},buttonDev: Button { text:'D', alignment:['center', 'center']},},  buttonUpdate: Button { text:'Update', alignment:['center', 'center']},     buttonExport: Button { text:'Export', alignment:['center', 'center']},     ButtonClose: Button { text:'Close', alignment:['center', 'center']}}";
    var win = new Window(windowResource);
   
    win.ButtonClose.onClick = function() { win.close() };
   
    win.panelSNumObjects.Group1.CheckSourse.onClick = function () {
        win.panelSNumObjects.Group1.CheckSourse.value = true;
        win.panelSNumObjects.Group2.CheckDest.value = false;
        setDocument('Source_l.ai', 0);
    };
   
    win.panelSNumObjects.Group2.CheckDest.onClick = function () {
        win.panelSNumObjects.Group1.CheckSourse.value = false;
        win.panelSNumObjects.Group2.CheckDest.value = true;
        setDocument('Dest_l.ai', 1);
    };
   
    function setDocument(documentName, layerIndex) {
        app.documents.getByName(documentName).activate();
        app.activeDocument.activeLayer = app.activeDocument.layers[layerIndex];
        app.redraw();
    }
    win.show();
 };

var message = WinObject.toString();
 
message += "\nnew WinObject();"

var bt = new BridgeTalk();
bt.target = "illustrator";
bt.body = message;
bt.send();
---------------------------------------------------------------------------------------------------
TOPICS
Scripting

Views

82

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

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.

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

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();
}

 

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

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

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
Community Expert ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

LATEST

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

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