Dropdown selection to string

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Chris Perrella

Dropdown selection to string

Post by Chris Perrella »

Hey guys, Im trying to return the selection of a dropdown as a string, and I cant get it working. Here is my test code.

Code: Select allfunction window(){

//local material array for wip

var materials= {};   
materials['test'] = [[50, 56], [0, 255]];

var win = new Window('dialog', 'Create Material Type',{x:100, y:100, width:500, height:100});
win.orientation='row';
win.main= win.add('panel', {x:15, y:15, width:470, height:70}, 'Select a Material Type');
win.cancelBtn = win.add('button', {x:390, y:45, width:75, height:20},'Cancel', {name:'cancel'});
win.runBtn = win.add('button', {x:300, y:45, width:75, height:20},'Run', {name:'ok'});
win.dropdown = win.main.add('dropdownlist', {x:15, y:23, width:250, height:20}, 'test');
for(var a in materials){
    win.dropdown.add('item', [a]);
    }
win.dropdown.selection=0;
win.onClick = function (){
 //convert to string and return index of dropdown?
var selectionstring = win.dropdown.selection.toString();
win.close(0);
return selectionstring;
}
win.center();
win.show();
}


Its the function after onClick that I am struggling with, any help would be great, thanks.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Dropdown selection to string

Post by pfaffenbichler »

What about the Array »materials«?
Does this help?
Code: Select allvar aa = window();
alert (aa);

function window(){

//local material array for wip

var materials = [[50, 56], [0, 255]];

var win = new Window('dialog', 'Create Material Type',{x:100, y:100, width:500, height:100});
win.orientation='row';
win.main= win.add('panel', {x:15, y:15, width:470, height:70}, 'Select a Material Type');
win.cancelBtn = win.add('button', {x:390, y:45, width:75, height:20},'Cancel', {name:'cancel'});
win.runBtn = win.add('button', {x:300, y:45, width:75, height:20},'Run', {name:'ok'});
win.dropdown = win.main.add('dropdownlist', {x:15, y:23, width:250, height:20}, 'test,');
for(var a in materials){
    win.dropdown.add('item', materials[a]);
    };
win.dropdown.selection=0;
win.center();
win.show();
var selectionstring = win.dropdown.selection.toString();
return selectionstring;
};
Mike Hale

Dropdown selection to string

Post by Mike Hale »

I think you should use the text property of selection. i.e. win.dropdown.selection.text
Chris Perrella

Dropdown selection to string

Post by Chris Perrella »

Totally forgot to update, but I did get this to work

function window(materials){
var win = new Window('dialog', 'Create a Material',{x:100, y:100, width:500, height:100});
win.orientation='row';
win.main= win.add('panel', {x:15, y:15, width:470, height:70}, 'Select your Material');
win.cancelBtn = win.add('button', {x:390, y:45, width:75, height:20},'Cancel', {name:'cancel'});
win.runBtn = win.add('button', {x:300, y:45, width:75, height:20},'Run', {name:'ok'});
win.dropdown = win.main.add('dropdownlist', {x:15, y:23, width:250, height:20}, 'test,');
for(var a in materials){
win.dropdown.add('item', [a]);
};
win.dropdown.selection=0;
win.center();
win.show();
var selectionstring = win.dropdown.selection.toString();
return selectionstring;

};