使用Photoshop脚本创建一个带有3个按钮的面板

时间:2017-12-14 12:11:18

标签: javascript photoshop-script photoshop-cs5

我想创建一个包含3个按钮的面板:

  1. 按钮 - 添加图片1
  2. 按钮 - 添加图片2
  3. 取消
  4. var dlg = new Window( "dialog", "Alert Box Builder" );
    dlg.btnPnl = dlg.add( "panel", undefined, "Build it" );
    dlg.btnPnl.testBtn = dlg.btnPnl.add( "button", undefined, "Test" );
    dlg.btnPnl.buildBtn = dlg.btnPnl.add( "button", undefined, "Build", {name: "ok" } );
    dlg.btnPnl.cancelBtn = dlg.btnPnl.add( "button", undefined, "Cancel", { name: "cancel" } );
    dlg.show();
    

1 个答案:

答案 0 :(得分:1)

你走在正确的轨道上!这样做只需要再添加一个按钮,然后为按钮添加一个特殊的onClick功能。该函数将打开操作系统的文件浏览器,然后将文件分配给pic1Filepic2File变量。

#target photoshop
var pic1File;
var pic2File;

var dlg = new Window( "dialog", "Alert Box Builder" );
btnPnl = dlg.add( "panel", undefined, "Build it" );
pic1Btn = btnPnl.add( "button", undefined, "Image 1" );
pic2Btn = btnPnl.add( "button", undefined, "Image 2" );
buildBtn = btnPnl.add( "button", undefined, "Build", {name: "ok" } );
cancelBtn = btnPnl.add( "button", undefined, "Cancel", { name: "cancel" } );

pic1Btn.onClick = function() {
    pic1File = new File;
    pic1File = pic1File.openDlg ( "Select Background Image", "Images: *.png; *.jpeg; *.jpg" )
    if( pic1File != null ) { pic1Btn.text = File.decode ( pic1File.name ) }
    else { 
        pic1File = new File;
        pic1Btn.text = "No file selected";
    }
}

pic2Btn.onClick = function() {
    pic2File = new File;
    pic2File = pic2File.openDlg ( "Select Background Image", "Images: *.png; *.jpeg; *.jpg" )
    if( pic2File != null ) { pic2Btn.text = File.decode ( pic2File.name ) }
    else { 
        pic2File = new File;
        pic2Btn.text = "No file selected";
    }
}

dlg.show();

希望有所帮助!