3 Replies Latest reply on May 31, 2012 11:05 AM by AdrianBentley

    Export script is slow

    AdrianBentley Level 1

      So we've written this export script which takes a specific set of layers (~10) and goes through the following steps:

       

      1. makes correct layers visible,

      2. Select all, copy merged.

      3. Create new document.

      4. Paste and futz with alpha/layers.

      5. Save new document.

       

      I can elaborate if need be.

       

      This takes around 40 seconds for 10 layers, which is a bit ridiculous.  How should I speed things up?  Is there a way to do such selective copy merged behavior much faster in a C++ exporter?  Can I turn off the UI so it doesn't have to refresh?

       

      Thanks,

      Adrian

        • 1. Re: Export script is slow
          AdrianBentley Level 1

          Oh I should note that we're still using CS5 with Javascript for the export script.

          • 2. Re: Export script is slow
            dgolberg Level 1

            It's kind of hard to say without knowing the exact process and/or script that's running.  One thing you might want to at least try, though, is; rather than creating a new document, simply have the script create a history state, do all the work you need to do, save, then restore the history state and do the next set.  Moving things between documents can sometimes take an extra second or 2 depending on the machine and the content being moved, where "temp" deleting extras and then going back in history isn't quite as slow.  Beyond that, we'd have to see the process/script to see if there are any inefficiencies that can be removed/worked around.  If nothing's found there, all that's left to look at are the specs of the computer the script is running on.  If the images are extra high resolution, it's likely to slow any machine down; especially during anything such as a transform or save/load process, but a faster processor and more ram generally helps with most things, while a solid state drive will help a lot with saves and loads.

             

            Anyway, hope this at least helps you narrow it down and determine if it's something that even can be sped up (if the files are super high resolution, it might not be possible).

            • 3. Re: Export script is slow
              AdrianBentley Level 1

              Here's the fullish pseudocode:

               

              hide all top level layers

              for each layer which matches our naming convention:

                show layer

                if layer is not itself layered (named *_LAYERS):

                  show rgb channels

                  select all

                  copy merged

                  create new file, clear layers

                  paste and flatten

                  save file

                  read file and merge into binary output file

                else:

                  hide all sub layers

                  for each sub layer group:

                    turn on sub layer group

                    hide levels layer at the top of each group (and keep name)

                    show rgb channels

                    select all

                    copy merged

                    create new file

                    paste

                    delete background layer

                    crack alpha into layer mask

                    select layer mask

                    make new channel (Alpha 1) from selection mask

                    delete layer mask

                    save file

                    read file and merge into binary output file

                    hide sub layer

                  show all sub layers

                  restore visibility of sublayers

              restore visibility of top level layers

              paste out binary output

               

              I can actually see the operations happening in photoshop (including changing layer visibility).  I would expect most of these to be too fast to see.  There are obvious pauses when new file and save occur, which make sense, but is still unfortunate.  I can try temporarily deleting parts of the file instead, though I'm a bit nervous about screwing up our source data.

               

              Is there a way to directly get access to the color data of a layer?  I only really need to get binary for color/alpha from a copy merged layer.

               

              Thanks,

              Adrian