I'm experimenting with a script that can add guides, and then separately, remove one of them. The upper half of the script is just a dialog with some variable names, particularly an editable text field.
Then there's a for-loop drawing several guides, followed by an event handler function and then the event handler itself.
I get an alert when I change the text field so this assures me the event handler function is successfully called, but for some reason, I have no idea why, the guide doesn't get removed. Can anyone fix this?
var myWindow = new Window("dialog");
var ProportionsGroup = myWindow.add("group");
ProportionsGroup.orientation = "column";
ProportionsGroup.alignment = "left";
ProportionsGroup.add("statictext", undefined, "Proportions (enter values between 0 and 1)");
var ProportionEntries = ProportionsGroup.add("group");
ProportionEntries.alignment = "left";
var ProportionA = ProportionEntries.add("edittext", undefined, "0.2");
ProportionA.characters = 6;
ProportionA.active = true;
var A = ProportionA.text;
var docWidth = Number(app.activeDocument.documentPreferences.pageWidth);
var docHeight = Number(app.activeDocument.documentPreferences.pageHeight);
for (var i = 1; i < 5; ++i) {
app.activeWindow.activePage.guides.add({name:"Blah"+i,location: docWidth*i*0.1, orientation: HorizontalOrVertical.VERTICAL});
}
function myEventHandler() {
alert("guide blah2: " + app.activeWindow.activePage.guides.itemByName("Blah2"));
app.activeWindow.activePage.guides.itemByName("Blah2").remove();
}
ProportionA.addEventListener('change', myEventHandler);
myWindow.show();