Having problems implementing radio buttons. I know radio buttons in CS2 can be problematic but I'm not sure where I am going wrong. I suspect I have a bracket or comma in the wrong place; but can't see it. Thank you.
var dlg =
"dialog {text:'Script Interface',bounds:[100,100,300,260]," +
"info: Group { orientation: 'column', alignChildren: 'center'," +
"radiobutton0:RadioButton {bounds:[50,30,150,40] , text:'layerName0', alignment: 'left' }," +
"radiobutton1:RadioButton {bounds:[50,50,150,90] , text:'layerName1', alignment: 'left' }}" +
"cancelBTN:Button{bounds:[110,130,190,150] , text:'Cancel' },"+
"processBTN:Button{bounds:[10,130,90,150] , text:'Ok' }}";
var win = new Window(dlg,"radio buttons");
win.radiobutton0.value = true;
win.center();
win.show();
Another thing: Is there a better way of writing UI elements as this format is rather ugly.
Here's the bare bones code that works. var dialogBox = "dialog { orientation: 'column', alignChildren: 'center', \ info: Group { orientation: 'column', alignChildren: 'center', \ rbtn1: RadioButton { text: 'Radio Button 1', align: 'left'}, \ rbtn2: RadioButton { text: 'Radio Button 2', align: 'left'}, }, }, \ } }";
win = new Window (dialogBox);
win.center();
win.show();
I think the radio button toggle is controlled by line 3 as commenting it out stops the radio buttons working correctly.
When I ran the code it threw an error on this line win.radiobutton0.value = true;
Object is undefined. This is because the way you have the dialog structured the button is part of the info
group within the window. The line should read
win.info.radiobutton0.value = true;
This should toggle radiobutton0 on initially.
You don't have to use a resource string to craft the dialogs if you don't want. Individual elements can be added by creating a reference to the window object (or to a pallate or panel) and using .add()
For example:
var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "Radio Button 1");
var radio2 = w.add ("radiobutton", undefined, "Radio Button 2");
radio1.value = true;
w.show ();
This is the most thorough reference on ScriptUI that I've found.