Sunday, August 26, 2007


ScriptUI Dialog with drop-down

I found the documentation for drop-down lists to be less easy to follow than for simpler objects. The script ended up being a lot simpler than I was at first led to believe by the combination of scant information in the Tools Guide and the structure of the object model. Here's what I ended up with:
//DESCRIPTION: Simple ScriptUI Drop-down List

listStrings = ["25%", "50%", "75%", "90%", "100%", "110%", "125%", "140%", "200%", "400%"];
myDlg = new Window('dialog', 'Drop-down List');
myDlg.orientation = 'column';
myDlg.alignment = 'right';
//add drop-down
myDlg.DDgroup = myDlg.add('group');
myDlg.DDgroup.orientation = 'row';
myDlg.DDgroup.add('statictext', undefined, "Zoom Percentage");
myDlg.DDgroup.DD = myDlg.DDgroup.add('dropdownlist', undefined, undefined, {items:listStrings})
myDlg.DDgroup.DD.selection = 4;
myDlg.closeBtn = myDlg.add('button', undefined, 'OK');
// add button functions
myDlg.closeBtn.onClick = function() {
result =;
I had the following difficulties:
  1. I didn't know how many undefineds to include in the add statement for the list. I arrived at two by trial and error. I imagine that the first one is for the dimension information. I'm not sure what the second one is.
  2. I expected to have to create an array of listItems for the items property of the drop-down, but the array of strings sufficed.
  3. I went through a number of hoops trying to work out how to set the initial value of the selection before stumbling on the simple use of the index to 100%.
  4. As a result of that, I was amazed to discover that the selection returns the selected value and not the index into the list.

Have you considered to use the scriptui resource language rather than coding all those initalizations? I can't yet recommend because I haven't tried it myself.
In response to point 4. If that alert had read:


then the index would have been returned.

To extract the number from the string, I could have used:

Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?