3 Replies Latest reply on Sep 19, 2015 10:50 AM by CarlosCanto

    iconbutton with four different images

    postworek111

      I try to build a button with image (iconbutton) to show rotation state.

      Screen Shot 2015-09-18 at 12.21.48.png    Screen Shot 2015-09-18 at 12.36.13.png

       

      When I click a button the letter in it should rotate and proper selection in dropdown list above should be displayed. I cannot get button to change its appearance using code attached below.

       

      var rotation = 1; // [0,1,2,3]
      
      var image = [];
          image[0] = ScriptUI.newImage("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CC\t\n\u00C00\bD\u00D1\u00AFfo\u00EB\u00FD\u008F\u009BI\u00A8 \u00F3@F2\u00B3AU\u00A0u\u00B0\u009F\u009DN\u00BB|1\u00C7/\x0B\u00B5\u00D1\x0F\x07\u008C\f\u0096X\u00B9S\u00C4 \u00CCL'\x1E>=Q\u00C1\u0099\u00CC\u00C3El\x01\x06\x00\u00A9|\x02\u00E0\u00B3?-3\x00\x00\x00\x00IEND\u00AEB`\u0082");
          image[1] = ScriptUI.newImage("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00FIDATx\u00DA,\u00CDK\x12\u00C0 \b\x03\u00D0\u00C8G\u00D1\u00B6\u00DC\u00FF\u00B8B\u0081\u00D5\u00CBL&`?\u00DE\x07\u0080\u00D5\u008A\u00FB\u008B$o\u00D2\u009D\u00C3X4\u0083\x03\u00A6#c\u00D2'\u00ADfV\u0086\u00E2H5\u00FF1\u00C8\u00A91&\u00EB\x17W\u0080\x01\x00\u00A4i\x02\u00E0,\x0B\u00CA\u00CE\x00\x00\x00\x00IEND\u00AEB`\u0082");
          image[2] = ScriptUI.newImage("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CB[\x12\u00C0 \bC\u00D1\x0B>P\u00DB\u00B2\u00FF\u00E5\x1A\u009D\u00E6'g`Ba\u00A52\u00998\u00F5\u00F0\u00E3a\u0080\u0099\x15J\u0092\u0095\u009B&.\x1D\u00F4\x1Ab\x06\u00BD\u009D\u0081\u00E8\u00B8\u00F1^v\u0082\u00C8\u00CB4\u00F0\u009F\r\u00BAj\x0B0\x00\u00932\x02\u00E0H\u00D6\u0089\u00F5\x00\x00\x00\x00IEND\u00AEB`\u0082");
          image[3] = ScriptUI.newImage("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00EIDATx\u00DA,\u008C1\x02\u00C00\b\x02Qcb\u00D2\u00D6\u00FF?\u00B7T\u00CBr7\x00\u00C8N\u00A8\u00A1\u00E4\f0\u0099S\x179\x0E\\H\u0083d\u0092Kg\u00FE\n\u00F1(\u00ED&\u008C\u00CA\u00FD\u00FD\u00ED\u009F\u00DDg\u00E1Vg\u009Dk\u00BF\x02\f\x00\u0098E\x02\u00E0\u00FF\u00B7\u00D3\x1A\x00\x00\x00\x00IEND\u00AEB`\u0082");
      
      
      
      var w = new Window ("dialog");  
          var rotationDropdown = w.add ("dropdownlist", undefined, ["0°", "90°", "180°", "270°"]);
              rotationDropdown.selection = rotation;
      
          var button = w.add ("iconbutton", undefined, image[rotation]); 
         
          button.onClick = function(){
              rotation++;
              if (rotation > 3) {
                  rotation = 0;
              }
              rotationDropdown.selection = rotation;
              button.icon = image[rotation];
          };
      
      
      w.show ();   
      
      

       

       

      When I save image temporary on disk button behaves correctly but ESTK freezes after script execution. Also, I can't remove temp images until end of executing which is undesirable because user can close window without executing rest of the script and images are left on disk. I discovered that freezes has something to do with array of images, but changing it leads to version above, which doesn't work.

       

      Code with temp images.

      var rotation = 1; // [0,1,2,3]
      
      var rysunek = [];
          rysunek[0] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CC\t\n\u00C00\bD\u00D1\u00AFfo\u00EB\u00FD\u008F\u009BI\u00A8 \u00F3@F2\u00B3AU\u00A0u\u00B0\u009F\u009DN\u00BB|1\u00C7/\x0B\u00B5\u00D1\x0F\x07\u008C\f\u0096X\u00B9S\u00C4 \u00CCL'\x1E>=Q\u00C1\u0099\u00CC\u00C3El\x01\x06\x00\u00A9|\x02\u00E0\u00B3?-3\x00\x00\x00\x00IEND\u00AEB`\u0082";
          rysunek[1] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00FIDATx\u00DA,\u00CDK\x12\u00C0 \b\x03\u00D0\u00C8G\u00D1\u00B6\u00DC\u00FF\u00B8B\u0081\u00D5\u00CBL&`?\u00DE\x07\u0080\u00D5\u008A\u00FB\u008B$o\u00D2\u009D\u00C3X4\u0083\x03\u00A6#c\u00D2'\u00ADfV\u0086\u00E2H5\u00FF1\u00C8\u00A91&\u00EB\x17W\u0080\x01\x00\u00A4i\x02\u00E0,\x0B\u00CA\u00CE\x00\x00\x00\x00IEND\u00AEB`\u0082";
          rysunek[2] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CB[\x12\u00C0 \bC\u00D1\x0B>P\u00DB\u00B2\u00FF\u00E5\x1A\u009D\u00E6'g`Ba\u00A52\u00998\u00F5\u00F0\u00E3a\u0080\u0099\x15J\u0092\u0095\u009B&.\x1D\u00F4\x1Ab\x06\u00BD\u009D\u0081\u00E8\u00B8\u00F1^v\u0082\u00C8\u00CB4\u00F0\u009F\r\u00BAj\x0B0\x00\u00932\x02\u00E0H\u00D6\u0089\u00F5\x00\x00\x00\x00IEND\u00AEB`\u0082";
          rysunek[3] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00EIDATx\u00DA,\u008C1\x02\u00C00\b\x02Qcb\u00D2\u00D6\u00FF?\u00B7T\u00CBr7\x00\u00C8N\u00A8\u00A1\u00E4\f0\u0099S\x179\x0E\\H\u0083d\u0092Kg\u00FE\n\u00F1(\u00ED&\u008C\u00CA\u00FD\u00FD\u00ED\u009F\u00DDg\u00E1Vg\u009Dk\u00BF\x02\f\x00\u0098E\x02\u00E0\u00FF\u00B7\u00D3\x1A\x00\x00\x00\x00IEND\u00AEB`\u0082";
      
      var fui = [];
      
      for (i = 0; i < rysunek.length; i++) {
         var myFile = new File(File($.fileName).path + "/rys" + i + ".png");
          myFile.encoding = "BINARY";
          myFile.open( "w" );
          myFile.write( rysunek[i] );
          myFile.close();
         
          fui[i] = File (File($.fileName).path + "/rys" + i + ".png");
      }
      
      
      
      var w = new Window ("dialog");  
          var rotationDropdown = w.add ("dropdownlist", undefined, ["0°", "90°", "180°", "270°"]);
              rotationDropdown.selection = rotation;
      
          var button = w.add ("iconbutton", undefined, ScriptUI.newImage(fui[rotation])); 
         
          button.onClick = function(){
              rotation++;
              if (rotation > 3) { rotation = 0; }
              rotationDropdown.selection = rotation;
              button.icon = ScriptUI.newImage(fui[rotation]);
          };
      
      
      w.show ();    
      
      

       

      Any other method to make button behave correctly?

        • 1. Re: iconbutton with four different images
          CarlosCanto Adobe Community Professional & MVP

          I tried but couldn't make it work without writing the png string to file, more work needs to be put into it...

           

          what I have seen other great scripters (marc is one of them) do, is they write the png string to file, each time the file is needed, update the button image, delete the image file right away, no file left behind...so they might have run into the very same problem you have now.

           

          var rotation = 1; // [0,1,2,3] 
          
          var rysunek = []; 
              rysunek[0] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CC\t\n\u00C00\bD\u00D1\u00AFfo\u00EB\u00FD\u008F\u009BI\u00A8 \u00F3@F2\u00B3AU\u00A0u\u00B0\u009F\u009DN\u00BB|1\u00C7/\x0B\u00B5\u00D1\x0F\x07\u008C\f\u0096X\u00B9S\u00C4 \u00CCL'\x1E>=Q\u00C1\u0099\u00CC\u00C3El\x01\x06\x00\u00A9|\x02\u00E0\u00B3?-3\x00\x00\x00\x00IEND\u00AEB`\u0082"; 
              rysunek[1] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00FIDATx\u00DA,\u00CDK\x12\u00C0 \b\x03\u00D0\u00C8G\u00D1\u00B6\u00DC\u00FF\u00B8B\u0081\u00D5\u00CBL&`?\u00DE\x07\u0080\u00D5\u008A\u00FB\u008B$o\u00D2\u009D\u00C3X4\u0083\x03\u00A6#c\u00D2'\u00ADfV\u0086\u00E2H5\u00FF1\u00C8\u00A91&\u00EB\x17W\u0080\x01\x00\u00A4i\x02\u00E0,\x0B\u00CA\u00CE\x00\x00\x00\x00IEND\u00AEB`\u0082"; 
              rysunek[2] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00HIDATx\u00DA,\u00CB[\x12\u00C0 \bC\u00D1\x0B>P\u00DB\u00B2\u00FF\u00E5\x1A\u009D\u00E6'g`Ba\u00A52\u00998\u00F5\u00F0\u00E3a\u0080\u0099\x15J\u0092\u0095\u009B&.\x1D\u00F4\x1Ab\x06\u00BD\u009D\u0081\u00E8\u00B8\u00F1^v\u0082\u00C8\u00CB4\u00F0\u009F\r\u00BAj\x0B0\x00\u00932\x02\u00E0H\u00D6\u0089\u00F5\x00\x00\x00\x00IEND\u00AEB`\u0082"; 
              rysunek[3] = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\u00BA\u00EC?\u008F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x00-PLTE\x00\x00\x00DDD\u0088\u0088\u0088333fff\u0099\u0099\u0099\u00DD\u00DD\u00DD\"\"\"\u00EE\u00EE\u00EEwww\u00AA\u00AA\u00AA\u00CC\u00CC\u00CC\u00BB\u00BB\u00BB\x11\x11\x11\u00FF\u00FF\u00FF\u00BF\u00D6\u00C7\u00C3\x00\x00\x00\x0FtRNS\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\x00\u00D4\u00DC\u0098\u00A1\x00\x00\x00EIDATx\u00DA,\u008C1\x02\u00C00\b\x02Qcb\u00D2\u00D6\u00FF?\u00B7T\u00CBr7\x00\u00C8N\u00A8\u00A1\u00E4\f0\u0099S\x179\x0E\\H\u0083d\u0092Kg\u00FE\n\u00F1(\u00ED&\u008C\u00CA\u00FD\u00FD\u00ED\u009F\u00DDg\u00E1Vg\u009Dk\u00BF\x02\f\x00\u0098E\x02\u00E0\u00FF\u00B7\u00D3\x1A\x00\x00\x00\x00IEND\u00AEB`\u0082"; 
          
          
          var w = new Window ("dialog");   
              var rotationDropdown = w.add ("dropdownlist", undefined, ["0°", "90°", "180°", "270°"]); 
                  rotationDropdown.selection = rotation; 
          
              var button = w.add ("iconbutton", undefined, ScriptUI.newImage(rysunek[rotation])); 
             
              button.onClick = function(){ 
                  rotation++; 
                  if (rotation > 3) { rotation = 0; } 
                 
                var myFile2 = new File(Folder.desktop+'/buttonimage.png'); 
                  myFile2.encoding = "BINARY"; 
                  myFile2.open( "w" ); 
                  myFile2.write( rysunek[rotation] ); 
                  myFile2.close(); 
                 
                 
                  rotationDropdown.selection = rotation; 
                  button.image = ScriptUI.newImage(myFile2.fsName);
                  myFile2.remove();
              }; 
          
          
          w.show ();
          
          • 2. Re: iconbutton with four different images
            postworek111 Level 1

            Using temporary images is not a problem. I couldn't figure out how to delete them after using in button. And you have found clever solution to generate button's image in time of clicking and than delete it.

             

            But, as I wrote, I have a problem with ESTK freezing when executing this code. This is to say after I cancel window with escape key executing does not stop (as it normally does) and clicking on stop button does nothing. Only way to do anything is to quit ESTK. Have you encountered similar behavior?

             

            I'm using CS6 on mac.

            • 3. Re: iconbutton with four different images
              CarlosCanto Adobe Community Professional & MVP

              I had no problem while testing, not a single freeze, try running straight from illustrator. I'm using Windows 8, CC2014