I’m having a bit of trouble figuring out how to call on a selected radio button. There are examples out there but they don’t seem to work with what I’m trying to do.
My script takes a template psd file opens it and changes some of the text layers based on the users selection.
I’m trying to use switch() for the radio buttons, but I have my button name as variable x. When I run the script, it gives me x is undefined. I understand that this means that I would need to define x before my switch(), but I’m not sure how to do this when the variable needs to be my case.
Here is the what I’m trying to use for the radio button.
switch (x.value=true){
case 'var x = dlg.pnl_projScheme.rdo_sn1':
app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('dlg.pnl_projScheme.rdo_sn1.text');
break;
case 'var x = dlg.pnl_projScheme.rdo_sn2':
app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('dlg.pnl_projScheme.rdo_sn2.text');
break;
case 'var x = dlg.pnl_projScheme.rdo_sn3':
app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('dlg.pnl_projScheme.rdo_sn3.text');
break;
case 'var x = dlg.pnl_projScheme.rdo_snNone':
app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('');
break;
}
Here’s my dialogue box:
var dlg = new Window('dialog', 'PSD Creator', [100, 100, 500, 550] );
dlg.pnl_browse = dlg.add('panel', [10, 10, 390, 150], 'Browse');
dlg.pnl_browse.txt_staticPSD = dlg.pnl_browse.add('statictext' , [15, 10, 375, 30],'Select the project images folder:');
dlg.pnl_browse.btn_browsePSD = dlg.pnl_browse.add ('button', [15, 35, 60, 60], '...');
dlg.pnl_browse.txt_editPSD = dlg.pnl_browse.add('edittext' , [65, 35, 365, 55],'<Select the project images folder>');
dlg.pnl_browse.txt_staticTIFF = dlg.pnl_browse.add('statictext' , [15, 70, 375, 90],'Select the folder where you TIFF images are:');
dlg.pnl_browse.btn_browseTIFF = dlg.pnl_browse.add ('button', [15, 95, 60, 120], '...');
dlg.pnl_browse.txt_editTIFF = dlg.pnl_browse.add('edittext' , [65, 95, 365, 120],'<Select the folder where you TIFF images are>');
dlg.pnl_projScheme = dlg.add('panel', [10,240,390,310], 'Details');
dlg.pnl_projScheme.txt_sn = dlg.pnl_projScheme.add('statictext' , [15,10,375,30],'Scheme:');
dlg.pnl_projScheme.rdo_snNone = dlg.pnl_projScheme.add('radiobutton' , [15,30,90,50],'None');
dlg.pnl_projScheme.rdo_sn1 = dlg.pnl_projScheme.add('radiobutton' , [100,30,180,50],'Scheme 1');
dlg.pnl_projScheme.rdo_sn2 = dlg.pnl_projScheme.add('radiobutton' , [190,30,270,50],'Scheme 2');
dlg.pnl_projScheme.rdo_sn3 = dlg.pnl_projScheme.add('radiobutton' , [280,30,360,50],'Scheme 3');
dlg.pnl_projScheme.rdo_snNone.value = true;
dlg.pnl_projOpt = dlg.add('panel', [10,320,390,390], 'Options');
dlg.pnl_projOpt.txt_sn = dlg.pnl_projOpt.add('statictext' , [15,10,375,30],'Option:');
dlg.pnl_projOpt.rdo_onNone = dlg.pnl_projOpt.add('radiobutton' , [15,30,90,50],'None:');
dlg.pnl_projOpt.rdo_on1 = dlg.pnl_projOpt.add('radiobutton' , [100,30,180,50],'Option 1:');
dlg.pnl_projOpt.rdo_on2 = dlg.pnl_projOpt.add('radiobutton' , [190,30,270,50],'Option 2:');
dlg.pnl_projOpt.rdo_on3 = dlg.pnl_projOpt.add('radiobutton' , [280,30,360,50],'Option 3:');
dlg.pnl_projOpt.rdo_onNone.value = true;
dlg.btn_ok = dlg.add ('button', [70,400,190,430], 'ok');
dlg.btn_cancel = dlg.add ('button', [210,400,320,430], 'cancel');
////////////////////////////
dlg.pnl_browse.btn_browsePSD.onClick = function () {
selectFilePSD = File.openDialog("Please select your template file.","*.psd");
if(selectFilePSD != null) dlg.pnl_browse.txt_editPSD.text = decodeURI(selectFilePSD.fsName);
}
dlg.pnl_browse.btn_browseTIFF.onClick = function () {
selectFileTIFF = File.openDialog("Please select your tiff images.","*.TIF; *TFF", true);
if(selectFileTIFF != null) dlg.pnl_browse.txt_editTIFF.text = decodeURI(selectFileTIFF.fsName);
}
dlg.btn_ok.onClick = function () {
selectFolderPSDs = Folder.selectDialog("Where do you want to save your PSDs?");
if(selectFolderPSDs != null) imageLocation = decodeURI(selectFolderPSDs.fsName);
dlg.close()
open (selectFilePSD);
if (dlg.pnl_projScheme.rdo_snNone.value = true) {
var r = "";
alert("");
}
if (dlg.pnl_projScheme.rdo_sn1.value = true) {
var r = dlg.pnl_projScheme.rdo_sn1.text;
alert(dlg.pnl_projScheme.rdo_sn1.text);
}
if(dlg.pnl_projScheme.rdo_sn2.value = true) {
var r = dlg.pnl_projScheme.rdo_sn2.text;
alert(dlg.pnl_projScheme.rdo_sn2.text);
}
if (dlg.pnl_projScheme.rdo_sn3.value = true) {
var r = dlg.pnl_projScheme.rdo_sn3.text;
alert(dlg.pnl_projScheme.rdo_sn3.text);
}
}
///////////////////////////
dlg.center();
dlg.show();
2
Answers
I think I figured it out, seems to work.
You’ve just had a typo in
if (dlg.pnl_projScheme.rdo_snNone.value = true)
, it should beif (dlg.pnl_projScheme.rdo_snNone.value == true)
with double'=='