4 Replies Latest reply on Dec 16, 2015 2:13 AM by Loic.Aigon

    How to do a indeterminate checkbox with script UI

    creativejoan0425 Level 1

      there are actually three states a checkbox can be in: checked, unchecked, or indeterminate. but the value only show true or false

       

      w = new Window ("dialog");

      e = w.add ("checkbox", undefined, "test");

      e.indeterminate = true;

      w.show();

        • 1. Re: How to do a indeterminate checkbox with script UI
          Loic.Aigon Adobe Community Professional

          Hi,

           

          Don't think you can achieve this through the native Checkbox. Only workaround I can't think of is using a pseudo checkbox of your own like an 3 state image. Youc could get inspired by Marc Autret's work on using sprites in ScriptUI :

          http://www.indiscripts.com/post/2011/04/sprite-buttons-in-scriptui

           

          You can cook something based on events to deal with sprite states

          http://www.ozalto.com/en/event-driven-programming-with-extendscript/

           

          HTH

           

          Loic

          www.ozalto.com

          • 2. Re: How to do a indeterminate checkbox with script UI
            creativejoan0425 Level 1

            thanks I want to ask how to change the png graphic to code?

            • 3. Re: How to do a indeterminate checkbox with script UI
              creativejoan0425 Level 1

              checkbox_value.png

              Below is my Script, when run and click 3 times, there will not show the image, can u fix it?

               

              // Number of vertical sprites

              // ---

              var V_SPRITES = 3;

               

               

              // InDesign CC Flag

              // ---

              const CC_FLAG = +(9 <= parseFloat(app.version));

               

               

              // ScriptUI Image Offset Fixer in InDesign CS6 and earlier

              // (This bug has been solved in CC i.e. ScriptUI 6.2.x)

              // ---

              const FIX_OFFSET = CC_FLAG ? 0 : 1;

               

               

              // Force an Image widget to repaint (= onDraw trigger)

              // CS4-CS6  ->  just reassigning this.size

              // CC       ->  we need to temporarily *change* the size

              // Note: using layout.layout(1) would not work anymore in CC

              // ---

              Image.prototype.refresh = CC_FLAG ?

                function()

                {

                var wh = this.size;

                this.size = [1+wh[0],1+wh[1]];

                this.size = [wh[0],wh[1]];

                wh = null;

                }:

                function()

                {

                this.size = [this.size[0],this.size[1]];

                };

              var myCheckboxValue = File("C:/Users/dtp/Desktop/UI_Checkbox_Graphic/checkbox_value.png");

               

               

                      var w = new Window("dialog","ScriptUI Sprites (CS4/CS5/CS6/CC)");

                              w.alignChildren = "left";

                      var myTopGroup = w.add ("group");

                             myTopGroup.alignChildren = ["fill","fill"];

                             myTopGroup.orientation = "row";

               

               

                          iButton = myTopGroup.add("image", undefined, myCheckboxValue, {state:0}),

                          iSize = iButton.image.size,

                          spriteHeight = iSize[1] / V_SPRITES;

                          iButton.size = [iSize[0], spriteHeight];

                         myTextIndentText = myTopGroup.add("statictext", undefined, "Text Indent")

               

               

               

               

               

               

               

               

               

               

               

              iButton.onDraw = function()

              {

                var dy = this.properties.state*spriteHeight + FIX_OFFSET;

                this.graphics.drawImage(this.image,0,-dy);

              };

               

               

              var mouseEventHandler = function(ev)

              {

                 

              //~ this.properties.state = ('mousedown'==ev.type)+2*('mousedown'==ev.type);

                this.properties.state = ('mousedown'==ev.type)+this.properties.state*('mousedown'==ev.type);

                this.refresh();

              //~     if(this.properties.state ==2){

              //~         this.properties.state =0;

              //~         this.refresh();

              //~         }

              };

              //~ iButton.addEventListener('mouseover', mouseEventHandler);

              iButton.addEventListener('mousedown', mouseEventHandler);

              //~ iButton.addEventListener('mouseup', mouseEventHandler);

              //~ iButton.addEventListener('mouseout', mouseEventHandler);

               

               

              w.show();

              • 4. Re: How to do a indeterminate checkbox with script UI
                Loic.Aigon Adobe Community Professional

                Hi,

                 

                if you comment out the useful parts, you can't expect it to work

                 

                if(this.properties.state ==3){
                
                this.properties.state =0;
                
                this.refresh();
                

                 

                Also you need to change 2 to 3

                 

                HTH

                 

                Loic