Skip to main content
Known Participant
June 6, 2010
Question

Delete all the channels faster

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

Ce sujet a été fermé aux réponses.

1 commentaire

c.pfaffenbichler
Community Expert
Community Expert
June 6, 2010

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.

Known Participant
June 6, 2010

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.

Inspiring
June 6, 2010

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();