5 Replies Latest reply on Jun 20, 2016 8:29 AM by c.pfaffenbichler

    How can I get "Snap To Pixels" current state?

    zeffir.design@gmail.com

      Hello community,

      Here is the function that creates a switch that manages "Snap To Pixels" option:

       

      index.html:

      <div id="STP_input" onclick="switchOnOff(this)">
           ...
      </div>
      

       

      main.js:

      $("#STP_input").click(function () {
           var a = switchOnOff(this);
           if (a) {
                csInterface.evalScript('switchSTP(true)');
           } else {
                csInterface.evalScript('switchSTP(false)');
           }
      });
      

       

      hostscript.jsx:

      function switchSTP(checkBTN) {
          'use strict';
          
          var condition;
          if (checkBTN === true) {
              condition = true;
          } else {
              condition = false;
          }
      
          var idsetd = charIDToTypeID( "setd" );
          var desc26 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref6 = new ActionReference();
              var idPrpr = charIDToTypeID( "Prpr" );
              var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
              ref6.putProperty( idPrpr, idtoolsPreferences );
              var idcapp = charIDToTypeID( "capp" );
              var idOrdn = charIDToTypeID( "Ordn" );
              var idTrgt = charIDToTypeID( "Trgt" );
              ref6.putEnumerated( idcapp, idOrdn, idTrgt );
          desc26.putReference( idnull, ref6 );
          var idT = charIDToTypeID( "T   " );
              var desc27 = new ActionDescriptor();
              var idtransformsSnapToPixels = stringIDToTypeID( "transformsSnapToPixels" );
              desc27.putBoolean( idtransformsSnapToPixels, condition );
          var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
          desc26.putObject( idT, idtoolsPreferences, desc27 );
          executeAction( idsetd, desc26, DialogModes.NO );
      
          return;
      }
      

       

      But when I hide panel and show it again, the switch goes back to the default state, only switch on my panel, not "Snap To Pixels" parameter on PS settings. Is it possible to get the current state of "Snap To Pixels" setting? How?

       

      Best regards.