4 Replies Latest reply on Dec 4, 2017 10:24 AM by AverinAAA

    Deleting channels is incredibly slow

    Bazsl Level 1

      Photoshop CC 2014 with all updates. My script saves two selections to two channels. At the end I delete the channels using the following function.

       

      function deleteChannelByName(channelNameToDelete) {

        var channelRef = activeDocument.channels.getByName(channelNameToDelete);

        channelRef.remove();

      }

       

      When I run the script in the Extend Script IDE  and call this function to delete a channel containing a selection a dialog with a green progress bar and the title "Rebuilding histogram..." appears nine, yes 9, times. This makes deleting a channel an unbelievably slow operation. Am I doing something wrong or is this just the way it is? Thanks.

        • 1. Re: Deleting channels is incredibly slow
          Bazsl Level 1

          I just discovered that I also get multiple displays of the "Rebuilding histogram..." progress dialog when I load a selection from a channel in one place in my script while in another part of the script I load a selection from a channel using the same code and do not get the "Rebuilding histogram..." dialogs. Very strange.

          • 2. Re: Deleting channels is incredibly slow
            DBarranca Level 4

            Hi,

            give this a try and let me know if it's quicker:

             

            function deleteChannelByName(channelName) {
                var desc = new ActionDescriptor(),
                    ref = new ActionReference();
                ref.putName( stringIDToTypeID("channel"), channelName );
                desc.putReference( stringIDToTypeID("target"), ref);
                executeAction( stringIDToTypeID("delete"), desc, DialogModes.NO );
            }
                
            // deleteChannelByName("aChannelToDelete");
            

             

            Regards,

             

            Davide Barranca

            ---

            www.davidebarranca.com

            www.cs-extensions.com

            • 3. Re: Deleting channels is incredibly slow
              Bazsl Level 1

              Thanks for the code Davide. It is similar to the code Script Listener generated but yours is shorter and it works perfectly. I also used Script Listener to generate code to load a selection from a channel and I no longer have the annoying "Rebuilding histogram..." dialogs anywhere.

               

              Bill

              • 4. Re: Deleting channels is incredibly slow
                AverinAAA Level 1

                It feels like `getByName` function is performing very slow

                I need following functionality:

                - select channel by name

                - create a channel if it doesn't exist already

                - remove channel

                - copy channel (that is, remove then duplicate with a new name)

                 

                How can I re-write it via photoshop script instead of using `channels.getByName`?