Copy link to clipboard
Copied
Hello everyvody
A little help..
I make this simple test script for Illustrator
At this point even if I press the cancel button the script continues to work..
How to make "cancel" button to stop the script. ...?
Thanks,
Nick Riviera
var doc = app.activeDocument;
function panel(){
var unit;
var units = ['mm',];
var panel = new Window("dialog", "test", undefined, { borderless: false });
panel.alignChildren = "left";
var r0 = panel.add ("group");
r0.add ('statictext {text: "unidades", characters: 8, justify: "left"}');
var dims = r0.add("dropdownlist", undefined, units);
dims.selection = dims.items[0];
var r1 = panel.add ("group");
r1.add ('statictext {text: "x", characters: 8, justify: "left"}');
var w = r1.add("edittext",undefined,"100");
w.characters = 10;
var r2 = panel.add ("group");
r2.add ('statictext {text: "h", characters: 8, justify: "left"}');
var h = r2.add("edittext",undefined,"50");
h.characters = 10;
var r6 = panel.add ("group");
r6.add("button", undefined, "OK");
r6.add("button", undefined, "Cancel");
unit = dims.selection.text;
x = Number(new UnitValue(w.text + " " + unit).as('pt'));
y = Number(new UnitValue(h.text + " " + unit).as('pt'));
panel.show();
}
function cR(){
doc.rulerOrigin = [0,0];
var layer2 = doc.layers.add();
layer2.name = "test";
rectangle = layer2.pathItems.rectangle(x, 0, y, x);
}
var rS = panel();
cR(rS);
Copy link to clipboard
Copied
Where you have "show()" inside your panel function, change it to:
if (panel.show() == 2) {
return null;
} else {
unit = dims.selection.text;
x = Number(new UnitValue(w.text + " " + unit).as('pt'));
y = Number(new UnitValue(h.text + " " + unit).as('pt'));
return { x : x, y : y };
}
When the Cancel button or Escape is pressed in a dialog it always returns a number 2. Anything else means something was pressed other than a Cancel button. Therefore, if the show() function returns a 2, return a null or a false value to let the following processes know that no valid user input was returned. If the rS variable is null, then do not run the cR() function.
Then, you must allow parameters to be passed into your cR() function. Currently there's no way it could know what x and y are. When you change the parameters to be something like cR(xy) and use the returned object as provided above, you can access the x and y by using xy.x and xy.y .
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
_
Copy link to clipboard
Copied
Thanks for reply, williamadowling
This is my modification...
var doc = app.activeDocument;
function panel(){
var unit;
var units = ['mm',];
var panel = new Window("dialog", "test", undefined, { borderless: false });
panel.alignChildren = "left";
var r0 = panel.add ("group");
r0.add ('statictext {text: "unidades", characters: 8, justify: "left"}');
var dims = r0.add("dropdownlist", undefined, units);
dims.selection = dims.items[0];
var r1 = panel.add ("group");
r1.add ('statictext {text: "x", characters: 8, justify: "left"}');
var w = r1.add("edittext",undefined,"100");
w.characters = 10;
var r2 = panel.add ("group");
r2.add ('statictext {text: "h", characters: 8, justify: "left"}');
var h = r2.add("edittext",undefined,"50");
h.characters = 10;
var r6 = panel.add ("group");
r6.add("button", undefined, "OK");
r6.add("button", undefined, "Cancel");
if (panel.show() == 2) {
return null;
} else {
unit = dims.selection.text;
x = Number(new UnitValue(w.text + " " + unit).as('pt'));
y = Number(new UnitValue(h.text + " " + unit).as('pt'));
return { x : x, y : y };
}
}
function cR(){
doc.rulerOrigin = [0,0];
var layer2 = doc.layers.add();
layer2.name = "test";
rectangle = layer2.pathItems.rectangle(x, 0, y, x);
}
var rS = panel();
cR(rS);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more