Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Delete all the channels faster

Community Beginner ,
Jun 05, 2010 Jun 05, 2010

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

TOPICS
Actions and scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 06, 2010 Jun 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2010 Jun 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 06, 2010 Jun 06, 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 25, 2013 Sep 25, 2013

yeah it's amazing fast!

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

windows version

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 25, 2013 Sep 25, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 25, 2013 Sep 25, 2013
LATEST

thanks

i use notepad++ , plain text is ansi

thank again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines