1 Reply Latest reply on Jan 16, 2015 4:05 PM by duanlook

    how rename  and sort spot channel by javascript?

    duanlook Level 1

      The name of a spot color channel is English letters or numbers.such aschannel is  a1 ,b3, ce, hh, ....or  vc, bg, kk, 1, 2, 3.....etc,.The spot color channel name,renamed in 1, 2, 3...

      exmple:

      1.

      spot channel name  a1 change to 1

      spot channel name   b3 change to 2

      spot channel name   ce change to 3

      spot channel name   hh change to 4

      .....

      2.

      spot channel name   vc   change to  1

      spot channel name   bg  change to   2

      spot channel name   kk  change to   3

      spot channel name   1   change to   4

      spot channel name   2   change to   5

      spot channel name   3   change to   6

      ......

        • 1. Re: how rename  and sort spot channel by javascript?
          duanlook Level 1

          i try to change by Getting Channel Information

           

          thx Michael L Hale

           

          change to:

          function getProperty( psClass, psKey, index ){// integer:Class, integer:key

              var ref = new ActionReference();

              if( psKey != undefined ) ref.putProperty( charIDToTypeID( "Prpr" ), psKey );

              if(index != undefined ){

                  ref.putIndex( psClass, index );

              }else{

                  ref.putEnumerated( psClass , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

              }

              try{

                  var desc = executeActionGet(ref);

              }catch(e){ return; }// return on error

              if(desc.count == 0) return;// return undefined if property doesn't exists

              var dataType = desc.getType(psKey);

              switch(dataType){// not all types supported - returns undefined if not supported

                  case DescValueType.INTEGERTYPE:

                      return desc.getInteger(psKey);

                      break;

                  case DescValueType.ALIASTYPE:

                      return desc.getPath(psKey);

                      break;

                  case DescValueType.BOOLEANTYPE:

                      return desc.getBoolean(psKey);

                      break;

                  case DescValueType.BOOLEANTYPE:

                      return desc.getBoolean(psKey);

                      break;

                  case DescValueType.UNITDOUBLE:

                      return desc.getUnitDoubleValue(psKey);

                      break;

                  case DescValueType.STRINGTYPE:

                      return desc.getString(psKey);

                      break;

                  case  DescValueType.OBJECTTYPE:

                      return desc.getObjectValue(psKey);

                      break;

                  case  DescValueType.LISTTYPE:

                      return desc.getList(psKey);

                      break;

                  case  DescValueType.ENUMERATEDTYPE:

                      return desc.getEnumerationValue(psKey);

                      break;

              }

          };

          var channelCount = app.activeDocument.channels.length;

          var channelNames = [];

          for(var channelIndex=1;channelIndex<=channelCount;channelIndex++){  

              var channelNames =getProperty(charIDToTypeID("Chnl"),charIDToTypeID("ChnN"),channelIndex);

          // =======================================================

          if(channelIndex==1){

          }

          else if(channelIndex==2){

          }

          else if(channelIndex==3){

          }

          else if(channelIndex==4){

          }

          else if(channelIndex>=5){

          var idslct = charIDToTypeID( "slct" );

              var desc329 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref246 = new ActionReference();

                  var idChnl = charIDToTypeID( "Chnl" );

                  ref246.putName( idChnl, ""+channelNames);

              desc329.putReference( idnull, ref246 );

          executeAction( idslct, desc329, DialogModes.NO );

          // =======================================================

          var idsetd = charIDToTypeID( "setd" );

              var desc330 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref247 = new ActionReference();

                  var idChnl = charIDToTypeID( "Chnl" );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idTrgt = charIDToTypeID( "Trgt" );

                  ref247.putEnumerated( idChnl, idOrdn, idTrgt );

              desc330.putReference( idnull, ref247 );

              var idT = charIDToTypeID( "T   " );

                  var desc331 = new ActionDescriptor();

                  var idNm = charIDToTypeID( "Nm  " );

                  desc331.putString( idNm, """"""+channelIndex-4 );

              var idSCch = charIDToTypeID( "SCch" );

              desc330.putObject( idT, idSCch, desc331 );

          executeAction( idsetd, desc330, DialogModes.NO );

          }

          }

           

          if spot channel name is number such as spot channel sequence: 2,1,3,6,8,9...can't success!...other success!