ScriptUI: How do I create a preview of the results while a palette is open?
My goal is to write a script that will draw a line, based on four coordinates of two points, which I enter into a palette. This is what I've got so far.
//Create palette to enter 4 coordinates of 2 points
#targetengine "session";
var window1 = new Window ("palette", "Line", undefined);
group1 = window1.add ("group");
group1.orientation = "row"; group1.alignment = "left";
group1.add ("statictext {text: 'Point 1', characters: 10, justify: 'left'}");
var entry1Text = group1.add ("edittext", undefined, "0");
entry1Text.characters = 3;
var entry2Text = group1.add ("edittext", undefined, "0");
entry2Text.characters = 3;
group2 = window1.add ("group");
group2.orientation = "row"; group1.alignment = "left";
group2.add ("statictext {text: 'Point 2', characters: 10, justify: 'left'}");
var entry3Text = group2.add ("edittext", undefined, "0");
entry3Text.characters = 3;
var entry4Text = group2.add ("edittext", undefined, "0");
entry4Text.characters = 3;
var checkbox = window1.add ("checkbox", undefined, "Preview");
checkbox.value = false;
window1.add ("button", undefined, "OK");
window1.show ();
//Convert input text into four numbers, x1, y1, x2 and y2
var x1 = parseInt (entry1Text.text); var y1 = parseInt (entry2Text.text);
var x2 = parseInt (entry3Text.text); var y2 = parseInt (entry4Text.text);
//Draw line based on x1, y1, x2 and y2
var path1 = documents[0].pathItems.add();
var point1 = path1.pathPoints.add();
point1.anchor = [x1, y1];
point1.rightDirection = [x1, y1]; point1.leftDirection = [x1, y1];
var point2 = path1.pathPoints.add();
point2.anchor = [x2, y2];
point2.rightDirection = [x2, y2]; point2.leftDirection = [x2, y2];
My question is: How do I create a preview of the results? I want to see the results "on the fly", with the palette still open, before I press OK, for example when I check a checkbox. Also, I want to be able to re-enter the data ad infinitum and see a preview until I am happy with the result, at which point I press OK and get the last result.
I'm three quarters of the way through Peter Kahrel's ScriptUI doc, but I can't find anything on how do do this and I've searched for the word "preview" in the rest of the doc, but didn't find anything.
I presume this is done through an event loop.
Your help is appreciated and thanks in advance.
