Copy link to clipboard
Copied
I have frequently have issues with getting ScriptUI dialogs to work. I am able to create the dialogs how I want but never seem to handle the onClick and user interaction functions correctly. In this script I used scriptui.joonas.me to generate some code. I'm able to get one of the onClick functions to work but not the other. Can anyone point out what I'm doing wrong?
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "INSP Snipe Creator";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
// GRP_TEXTFILE
// ============
var grp_textFile = dialog.add("group", undefined, {name: "grp_textFile"});
grp_textFile.orientation = "row";
grp_textFile.alignChildren = ["left","center"];
grp_textFile.spacing = 10;
grp_textFile.margins = 0;
var st_textFile = grp_textFile.add("statictext", undefined, undefined, {name: "st_textFile"});
st_textFile.text = "Text file";
var et_textFile = grp_textFile.add('edittext {properties: {name: "et_textFile"}}');
et_textFile.helpTip = "Path to the text file";
et_textFile.text = "Click button to choose data file";
et_textFile.preferredSize.width = 350;
var btn_loadFile = grp_textFile.add("button", undefined, undefined, {name: "btn_loadFile"});
btn_loadFile.helpTip = "click here to pick a text file.\nIt must be a tab delimited text file.";
btn_loadFile.text = "...";
btn_loadFile.onClick = function() {var dataFile = File.openDialog("Select a text file to open.", "")
et_textFile.text = dataFile.absoluteURI.replace("%20", " ");};
// DIALOG
// ======
var st_pastedText = dialog.add("group");
st_pastedText.orientation = "column";
st_pastedText.alignChildren = ["center","center"];
st_pastedText.spacing = 0;
st_pastedText.add("statictext", undefined, "-or- ", {name: "st_pastedText"});
st_pastedText.add("statictext", undefined, "", {name: "st_pastedText"});
st_pastedText.add("statictext", undefined, "Data from Spreadsheet", {name: "st_pastedText"});
var et_pastedText = dialog.add('edittext {properties: {name: "et_pastedText", multiline: true, scrollable: true}}');
et_pastedText.helpTip = "Copy and paste rows of data from excel. ";
et_pastedText.text = "Paste lines from Excel here";
et_pastedText.preferredSize.width = 800;
et_pastedText.preferredSize.height = 150;
// GRP_BUTTONS
// ===========
var grp_buttons = dialog.add("group", undefined, {name: "grp_buttons"});
grp_buttons.orientation = "row";
grp_buttons.alignChildren = ["center","center"];
grp_buttons.spacing = 25;
grp_buttons.margins = 0;
var btn_create = grp_buttons.add("button", undefined, undefined, {name: "btn_create"});
btn_create.helpTip = "Run the script and make the snipes";
btn_create.text = "CREATE SNIPES";
btn_create.preferredSize.width = 130;
btn_create.preferredSize.height = 30;
btn_create.alignment = ["center","center"];
btn_create.onClick = createSnipes;
var btn_help = grp_buttons.add("button", undefined, undefined, {name: "btn_help"});
btn_help.text = "?";
btn_help.onClick = clicked;
dialog.show();
function clicked(){ //this function works
alert("button click");
alert(dialog.grp_textFile.et_textFile.text);
}
function createSnipes(){ //this function does not work
var textInput = dialog.grp_textFile.et_pastedText.text;
alert("creating snipes now\n"+ textInput);
var pastedText = textInput.split("\t");
alert(pastedText[2]);
}
Copy link to clipboard
Copied
It looks like you added et_pastedText directly to dialog, so it can't find dialog.grp_textFile.et_pastedText.text
Copy link to clipboard
Copied
Thanks Dan. Often it takes going to all the trouble and having another set of eyes on the dang code to see the glaring error. <facepalm>