Changing the text in a scriptUI window
Copy link to clipboard
Copied
I'm sure it's trivial, but i cannot get it.
I've got his window displaying my document's name and a button that triggers an action (init)
When going to another illustrator document, since my init action checks the document's name, i'd love the script window to display the right name to avoid confusion.
I know how to build a dialogue, but i don't know how to update part of it (let's say a statictext)
see the code here, doing nothing but alert(doctitle) on click :
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global $, Folder*/
/*****************
Script Test
Par Franck Payen mars 2014
******************/
var doc; // document actif
var docTitle; // titre du document actif
function displayUI() {
var dialogue = new Window ("palette", "Afficher les calques ", undefined, {closeButton:true, resizeable: true});
dialogue.orientation = "column";
dialogue.alignChildren = "fill";
dialogue.margins = 10;
dialogue.location = [0,40];
dialogue.preferredsize = [200, 400];
// onResize needed on Mac OS X
dialogue.onResizing = dialogue.onResize = function () {this.layout.resize ();}
var groupe0 = dialogue.add ("group", undefined);
groupe0.orientation = "column";
groupe0.alignChildren = "fill";
var monDocTitle = groupe0.add ("statictext", undefined, docTitle);
var groupe2 = dialogue.add ("group", undefined);
groupe2.orientation = "column";
groupe2.alignChildren = "fill";
var boutonInit = groupe2.add ("button", undefined, "Reinitialiser");
boutonInit.onClick = function (){
var messageBT = new BridgeTalk();
messageBT.target = "illustrator";
var messageBTcorps = "initScript()";
messageBT.body = messageBTcorps;
messageBT.send();
};
dialogue.onClose = function (){
dialogue.hide();
};
//alert (dialogue); //will work and return [object Window]
dialogue.show();
};
function initScript(){
if (app.documents.length == 0){
alert("Merci d'ouvrir un document avant de lancer ce script.\nL'opération a été interrompue.", "Pas de document ouvert");
return;
};
doc = app.activeDocument;
docTitle = app.activeDocument.name.split(".")[0];
alert(docTitle);
//alert (dialogue); //won't work and refuse to launch the script
// displayUI(); // v1, lance le display après l'initialisation. Scindé pour utiliser le bouton réinitialiser.
}
#target Illustrator
#targetengine main
var versionAi = new Number (app.version.slice (0,2));
if (versionAi > 12){
initScript();
displayUI();
};
else
if (versionAi < 13){
alert("Ce script n'es pas compatible avec Illustrator CS2 ou des versions plus anciennes.\nL'opération a été interrompue.", "Version incompatible");
};
Explore related tutorials & articles
Copy link to clipboard
Copied
Franck Payen wrote:
I'm sure it's trivial, but i cannot get it.
no, it is not trivial, I found it was very difficult at first...
you need two things, have Illustrator return a value to bridgeTalk,
function initScript(){
if (app.documents.length == 0){
alert("Merci d'ouvrir un document avant de lancer ce script.\nL'opération a été interrompue.", "Pas de document ouvert");
return;
};
doc = app.activeDocument;
docTitle = app.activeDocument.name.split(".")[0];
return docTitle;
}
then have bridgeTalk read the returned value, then you can use it in your Palette
boutonInit.onClick = function (){
var messageBT = new BridgeTalk();
messageBT.target = "illustrator";
var messageBTcorps = "initScript()";
messageBT.body = messageBTcorps;
//**************************************************************
messageBT.onResult = function(returned) {
var docname = returned.body;
monDocTitle.text = docname;
dialogue.layout.layout(true);
}
//**************************************************************
messageBT.send();
};
Copy link to clipboard
Copied
Awesome.
Works as advertised !
Small question about the forum, what is the markup (down?) you use to get the code quote look clean ?
Copy link to clipboard
Copied
in your reply window, click on the "Use Advanced Editor" button
then you'll get more buttons, click on the "Insert" button and pick Syntax Highlight->Java

