6 Replies Latest reply on Sep 25, 2013 8:45 AM by Giovannivolontè

    Delete all the channels faster

    jboissinot Level 1

      Hi,

       

      I use the activeDocument.channels.removeAll() function for deleting all the channels, it works well but can be long.

      I have a 6K PSD file with 12 extra channels and it takes 2 min to remove them all.

      I'm looking for a way to delete all the channels faster.

      I tried with actions but I don't achieve to speed up this step.

      Is it possible to delete all the channels like the "Delete Hidden Layers" action which is quickly even with a huge PSD file containing many layers ? Or anything else ? If you have any idea or solution.

       

      Thanks

        • 1. Re: Delete all the channels faster
          c.pfaffenbichler Level 9

          You could do a saveAs and exclude the channels (PhotoshopSaveOptions.alphaChannels) – but I’m not sure it is much faster and you would have to replace and close the original file, I guess.

          • 2. Re: Delete all the channels faster
            jboissinot Level 1

            Yes it can be a solution. But I'm doing a clean-up of a PSD file before doing some export actions. It would be useful to have the possibility to duplicate a document without channels.

             

            Back to my problem, if I drag&drop all the channels I have selected by hand, it's fast. I could do this with an action but I need the channels name, and the problem is that parsing the channels is so long because of it gets channel objects.

            • 3. Re: Delete all the channels faster
              Michael L Hale Level 5

              The code below uses the Action Manager API to remove alpha and spot channels from a document. It should be faster than the DOM and as fast as possible with a script.

              function deleteAlphaAndSpotChannels(){
                   function isAlphaOrSpotChannel(){
                   var ref = new ActionReference();
                   ref.putEnumerated( charIDToTypeID("Chnl"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                   return executeActionGet(ref).hasKey( stringIDToTypeID('ID') );
                   }
                   function deleteChannelByIndex( idx ){
                        var desc = new ActionDescriptor();
                             var ref = new ActionReference();
                             ref.putIndex(charIDToTypeID( "Chnl" ), idx )
                        desc.putReference( charIDToTypeID( "null" ), ref );
                        executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
                   }
                   function getNumberOfChannels(){     
                        var ref = new ActionReference();
                        ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                        return executeActionGet(ref).getInteger( stringIDToTypeID('numberOfChannels'))// does not count layer masks
                   }
                   function numberOfComponentChannels(){     
                        var ref = new ActionReference();
                        ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                        var mode = typeIDToStringID( executeActionGet( ref ).getEnumerationValue( stringIDToTypeID('mode') ) );
                        var numberOfComponentChannels = 4;// set default for CMYK
                        switch ( mode ){
                             case "RGBColor":
                                  numberOfComponentChannels = 3;
                                  break;
                             case "labColor":
                                  numberOfComponentChannels = 3;
                                  break;
                             case "grayScale":
                                  numberOfComponentChannels = 1;
                                  break;
                        }
                        return numberOfComponentChannels;
                   }
                   while( getNumberOfChannels() > numberOfComponentChannels() ){
                        makeChannelActiveByIndex( getNumberOfChannels(), false );
                        if( isAlphaOrSpotChannel() ){
                             deleteChannelByIndex( getNumberOfChannels() );
                        }
                   }
                   function makeChannelActiveByIndex( idx, visible ){
                        var desc = new ActionDescriptor();
                             var ref = new ActionReference();
                             ref.putIndex(charIDToTypeID( "Chnl" ), idx)
                             desc.putReference( charIDToTypeID( "null" ), ref );
                             desc.putBoolean( charIDToTypeID( "MkVs" ), visible );
                        executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
                   }
              }
              deleteAlphaAndSpotChannels();
              
              • 4. Re: Delete all the channels faster
                Giovannivolontè Level 1

                yeah it's amazing fast!

                 

                a question should be in *.js , ansi or unicode?

                windows version

                thanks

                • 5. Re: Delete all the channels faster
                  Michael L Hale Level 5

                  Although the .js extension will work Adobe recommends using .jsx. Save as plain text.

                  • 6. Re: Delete all the channels faster
                    Giovannivolontè Level 1

                    thanks

                    i use notepad++ , plain text is ansi

                     

                    thank again!