Copy link to clipboard
Copied
Hi,
Does anyone know if there is a way to add buttons to an already running script UI when using an 'onClick' function of a persistent button?
I am trying to make a refresh button for a set of buttons that are created based on spot colours in a job, but need to be able to read different jobs as you change document.
I have managed to get the 'Refresh' button to delete the already created buttons based on the spot colours but need to be able to add them abck in from the new doc. I have tried the following but to no avail - do I need to do something to rebuild the whole palette etc.?:
RefreshColourList.onClick = function(){
var testButton = Colours.add("button", undefined, "Test");
testButton.text = "Test Button";
}
Many thanks in advance.
Hi,
You can use the following line
palette.layout.layout(true);
to refresh the layout. So your final RefreshColourList methood will look like
RefreshColourList.onClick = function () {
for (h = Colours.children.length - 1; h >= 0; h--) {
Colours.remove(Colours.children[h]);
}
var testButton = Colours.add("button", undefined, "Test");
testButton.text = "Test Button";
palette.layout.layout(true);
}
I hope it works for you.
Copy link to clipboard
Copied
Hi,
Yes I think so this is possible.
Could you please share the complete code?
Copy link to clipboard
Copied
Hi Charu,
Please see below for full code so far (this is still work in progress). It is lines 93 and 94 (that are commented out) that I am struggling with, the forcing back into the UI of new buttons:
var doc = app.activeDocument;
#target illustrator
#targetengine "main"
var palette = new Window("palette");
palette.text = "Spot Colours";
palette.orientation = "column";
palette.alignChildren = ["center","top"];
palette.spacing = 10;
palette.margins = 16;
var RefreshColourList = palette.add("button", undefined, undefined, {name: "RefreshColourList"});
RefreshColourList.text = "Refresh Colour List";
var Colours = palette.add("panel", undefined, undefined, {name: "Colours"});
Colours.text = "Colours";
Colours.orientation = "column";
Colours.alignChildren = ["left","top"];
Colours.spacing = 10;
Colours.margins = 10;
for (var i = 0; i < doc.spots.length; i++) {
if (doc.spots[i].name.match("PANTONE")) {
var buttonName = doc.spots[i].name;
var group1 = Colours.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var button1 = group1.add("button", undefined, undefined, {name: "Button_A"});
button1.text = buttonName;
button1.size = [150,30];
var button2 = group1.add("button", undefined, undefined, {name: "Button_B"});
button2.text = buttonName + "Colour";
button2.size = [30,30];
var lab = doc.spots[i].getInternalColor();
var labFinal = [];
lab2rgb(lab);
function lab2rgb(lab){
var y = (lab[0] + 16) / 116,
x = lab[1] / 500 + y,
z = y - lab[2] / 200,
r, g, b;
x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);
y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);
z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
b = x * 0.0557 + y * -0.2040 + z * 1.0570;
r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;
g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;
b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;
r = Math.round(Math.max(0, Math.min(1, r)) * 255);
g = Math.round(Math.max(0, Math.min(1, g)) * 255);
b = Math.round(Math.max(0, Math.min(1, b)) * 255);
labFinal.push(Math.round((r / 255) * 100) / 100);
labFinal.push(Math.round((g / 255) * 100) / 100);
labFinal.push(Math.round((b / 255) * 100) / 100);
button2.fillBrush = button2.graphics.newBrush(button2.graphics.BrushType.SOLID_COLOR, [labFinal[0],labFinal[1],labFinal[2]]);
button2.onDraw = customDraw;
}
}
}
function customDraw() {
with(this) {
graphics.drawOSControl();
graphics.rectPath(0,0,size[0],size[1]);
graphics.fillPath(fillBrush);
}
}
palette.show();
RefreshColourList.onClick = function(){
for (h = Colours.children.length - 1; h >= 0; h--) {
Colours.remove(Colours.children[h]);
}
// var testButton = Colours.add("button", undefined, "Test");
// testButton.text = "Test Button";
}
Copy link to clipboard
Copied
Hi,
You can use the following line
palette.layout.layout(true);
to refresh the layout. So your final RefreshColourList methood will look like
RefreshColourList.onClick = function () {
for (h = Colours.children.length - 1; h >= 0; h--) {
Colours.remove(Colours.children[h]);
}
var testButton = Colours.add("button", undefined, "Test");
testButton.text = "Test Button";
palette.layout.layout(true);
}
I hope it works for you.
Copy link to clipboard
Copied
Thank you, thank you, thank you. That is exactly what I have been after. Much appreciated.
Copy link to clipboard
Copied
You are welcome..😊