Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
User avatar
BartlomiejOtlowski
Topic Author
Posts: 4
Joined: Thu Nov 05, 2015 4:10 am
Location: Wroclaw, Poland
Contact:

Checkboxes and a button in the palette window

Fri Feb 19, 2016 2:24 am

Hi!
I want to make a window with 2 or more checkboxes and a button. Depends what is selected when I hit the button specific function will be executed. I don't know how to change values of the checkboxes in the opened script. It always has a value of runned script. No matter I select a checkbox or not. I tried something like this:

var myWin = new Window("palette", "My Window", undefined);
    myWin.orientation = "row";

var groupOne = myWin.add("group", undefined, "GroupOne");
    groupOne.orientation = "column";
    var check1 = groupOne.add("checkbox", undefined, "CheckBox #1");
    var check2 = groupOne.add("checkbox", undefined, "CheckBox #2");
    var button1 = groupOne.add("button", undefined, "Button");

 if (button1.value == 1){
        var myFunction = function(){
            alert1();
        }
}else{
        var myFunction = function(){
            alert2();
    }
}

function alert1(){
alert("ONE_ONE_ONE");
}

function alert2(){
alert("TWO_TWO_TWO");
}

button1.onClick = myFunction


myWin.center();
myWin.show();


Thank you for your help!
 
beginUndoGroup
Posts: 79
Joined: Tue Nov 27, 2012 6:41 am

Re: Checkboxes and a button in the palette window

Sat Feb 20, 2016 4:06 am

The button1.onClick must collect the current checkboxes values:

var myWin = new Window("palette", "My Window", undefined);
   myWin.orientation = "row";

var groupOne = myWin.add("group", undefined, "GroupOne");
   groupOne.orientation = "column";
   var check1 = groupOne.add("checkbox", undefined, "CheckBox #1");
   var check2 = groupOne.add("checkbox", undefined, "CheckBox #2");
   var button1 = groupOne.add("button", undefined, "Button");
   button1.onClick = function(){
      doStuff(check1.value, check2.value);
      };
function doStuff(option1, option2){
   var text = "";
   text += "option 1 enabled : " + option1;
   text += "\r";
   text += "option 2 enabled : " + option2;
   alert(text);
   };

myWin.center();
myWin.show();
 
User avatar
BartlomiejOtlowski
Topic Author
Posts: 4
Joined: Thu Nov 05, 2015 4:10 am
Location: Wroclaw, Poland
Contact:

Re: Checkboxes and a button in the palette window

Sun Feb 21, 2016 12:46 pm

Thank you!

Who is online

Users browsing this forum: No registered users and 1 guest