2017-09-28 66 views
1

我在查找如何調用所選單選按鈕時遇到了一些麻煩。有一些例子,但他們似乎沒有與我想要做的事情一起工作。Photoshop javascript;如何調用單選按鈕

我的腳本需要一個模板psd文件打開它並根據用戶選擇更改一些文本圖層。

我想使用開關()爲單選按鈕,但我有我的按鈕名稱作爲變量x。當我運行該腳本時,它給我x是未定義的。我知道這意味着我需要在switch()之前定義x,但是當變量需要成爲我的情況時,我不確定該如何做到這一點。

這是我試圖用於單選按鈕。

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; 
} 

這裏是我的對話框:

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(); 

回答

0

我想我想通了,似乎工作。

  switch(true) { 
      case dlg.pnl_projScheme.children[1].value: 
       app.activeDocument.layers.getByName("SCHEME").textItem.contents = (' '); 
       break; 
      case dlg.pnl_projScheme.children[2].value: 
       app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('Scheme 1'); 
       break; 
      case dlg.pnl_projScheme.children[3].value: 
       app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('Scheme 2'); 
       break; 
       case dlg.pnl_projScheme.children[4].value: 
       app.activeDocument.layers.getByName("SCHEME").textItem.contents = ('Scheme 3'); 
       break; 
      default: 
       app.activeDocument.layers.getByName("SCHEME").textItem.contents = (' --- '); 
     }