4 Replies Latest reply on Jul 10, 2016 7:55 AM by benjamin_weiler

    Painting Process Documentation: Stamp Visible, Move to layer Set and hide

    benjamin_weiler Level 2

      I like to capture my screen while painting and when I am done I make an animated GIF from these "process shots". I am trying to automatize the process and I have managed to come up with this which meets my needs:

       

      #target photoshop

      app.bringToFront();

       

       

      // Stamp visible Layers

      var idMrgV = charIDToTypeID( "MrgV" );

          var desc2 = new ActionDescriptor();

          var idDplc = charIDToTypeID( "Dplc" );

          desc2.putBoolean( idDplc, true );

      executeAction( idMrgV, desc2, DialogModes.NO );

       

       

      // Move Active Layer to the Bottom of LayerSet "process"

      var activeLayer = activeDocument.activeLayer;

          var processFolder = activeDocument.layerSets.getByName("process")

          activeDocument.activeLayer.moveToEnd (processFolder);

       

      Now I would like to add a conditional to check, whether or not the "process" layer-set exists and if it does not, create it. This should look something like this:

       

      // Process Image Capture

      // V 0.3

      // PIC Stamps Visible (creates a new layer that combines all visible information in flattened form) and moves that to a "process" Layer Set.

      // Layer is then hidden.

      // If Layer Set is not there, it will be created.

       

       

      #target photoshop

      app.bringToFront();

       

       

      // Check for "Process" Layer-Set on root. Create, in case it is not present.

      if (!activeDocument.layerSets.getByName("process")) {

           activeDocument.LayerSets.add();

           activeDocument.LayerSets.name = "process";

           }

      //

      /* else {

         

           }*/

       

       

      // Stamp visible Layers

      var idMrgV = charIDToTypeID( "MrgV" );

          var desc2 = new ActionDescriptor();

          var idDplc = charIDToTypeID( "Dplc" );

          desc2.putBoolean( idDplc, true );

      executeAction( idMrgV, desc2, DialogModes.NO );

       

       

      // Move Active Layer to the Bottom of LayerSet "process"

          var activeLayer = activeDocument.activeLayer;

          var processFolder = activeDocument.layerSets.getByName("process")

          activeDocument.activeLayer.moveToEnd (processFolder);

          activeDocument.activeLayer.visibility = false;

       

      The condition seems to be what causes the problem, but I have no idea how to fix it. Can somebody help?

        • 1. Re: Painting Process Documentation: Stamp Visible, Move to layer Set and hide
          xbytor2 Level 4

          Capitalization problems.
          These lines:

              activeDocument.LayerSets.add();
              activeDocument.LayerSets.name = "process";
          

           

          Should be

              activeDocument.layerSets.add();
              activeDocument.layerSets.name = "process";
          

           

          Not saying there is nothing else wrong, though....

          • 2. Re: Painting Process Documentation: Stamp Visible, Move to layer Set and hide
            benjamin_weiler Level 2

            Do you perchance know what kind of value would be returned by .layerSets.getByName("process") if there is no such Layer Set?


            Is it undefined? False? Null?

            How would I go about finding out?

            • 3. Re: Painting Process Documentation: Stamp Visible, Move to layer Set and hide
              benjamin_weiler Level 2

              Ok, here is the script that does the deed, it requires an additional function to catch what getByName() returns.

               

              // Process Image Capture

              // V 1.0

              // PIC Stamps Visible (creates a new layer that combines all visible information in flattened form) and moves that to a "process" Layer Set.

              // Layer is then hidden.

              // If Layer Set is not there, it will be created.

               

               

              #target photoshop

              app.bringToFront();

               

               

              // Check for "Process" Layer-Set on root. Create, in case it is not present.

              if (!hasRootLayer("process")) {   

                  var addedLayer = activeDocument.layerSets.add();

                  addedLayer.name = "process";

              }

               

               

              // Stamp visible Layers

              var idMrgV = charIDToTypeID( "MrgV" );

                  var desc2 = new ActionDescriptor();

                  var idDplc = charIDToTypeID( "Dplc" );

                  desc2.putBoolean( idDplc, true );

              executeAction( idMrgV, desc2, DialogModes.NO );

               

               

              // Move Active Layer to the Bottom of LayerSet "process"

                  var activeLayer = activeDocument.activeLayer;

                  var processFolder = activeDocument.layerSets.getByName("process")

                  activeDocument.activeLayer.moveToEnd (processFolder);

                  activeDocument.activeLayer.visibility = false;

               

               

              // Function to check whether "process" layer exists, passes result back as a boolean

                  function hasRootLayer(layerName){

                  var hasProcessLayer = false;

                  try{

                      hasProcessLayer = (typeof activeDocument.layerSets.getByName(layerName) != "undefined");

                  }catch(e){}

               

               

                  return hasProcessLayer;

              }

              • 4. Re: Painting Process Documentation: Stamp Visible, Move to layer Set and hide
                benjamin_weiler Level 2

                I upgraded this script to use layer IDs and it now does the following:

                1. Takes the shots of your work
                2. Puts them in a layer-set called "process
                3. Hides  the last shot you took
                4. Returns to the layer it was called from, ninja-style

                 

                You can then make easily make an animated GIF from the layer in the "process" layer-set, presto.

                 

                Enjoy Version 1.3:

                // Process Image Capture

                // V 1.3

                // PIC Stamps Visible (creates a new layer that combines all visible information in flattened form) and moves that to a "process" Layer Set.

                // Layer is then hidden.

                // If Process Layer Set is not there, it will be created.

                // Now remembers what layerSet or Layer it was called from and returns to it after placing process image

                // Fluff removed

                 

                 

                #target photoshop

                app.bringToFront();

                 

                 

                 

                 

                // Check for "Process" Layer-Set on root. Create, in case it is not present.

                if (!hasRootLayer("process")) {

                    var addedLayer = activeDocument.layerSets.add();

                    addedLayer.name = "process";

                }

                 

                 

                // Container to hold Layer ID of active Layer at moment of script execution

                var callLayer =  getActiveLayerId(activeDocument.activeLayer);

                alert(callLayer, "calling Layer:");

                 

                 

                // Stamp visible Layers

                var idMrgV = charIDToTypeID( "MrgV" );

                var descMerge = new ActionDescriptor();

                var idDplc = charIDToTypeID( "Dplc" );

                descMerge.putBoolean( idDplc, true );

                executeAction( idMrgV, descMerge, DialogModes.NO );

                 

                 

                // Move Active Layer to the Bottom of LayerSet "process" and hide

                var activeLyr = activeDocument.activeLayer;

                var processFolder = activeDocument.layerSets.getByName("process");

                activeDocument.activeLayer.moveToBeginning (processFolder);

                activeDocument.activeLayer.visible = false;

                 

                 

                // Return Focus to Layer from which Action was called

                makeActiveByID(callLayer);

                 

                 

                // Check whether "process" layerSet exists, passes result back as a boolean

                function hasRootLayer(layerName){

                    var hasProcessLayer = false;

                    try{

                        hasProcessLayer = (typeof activeDocument.layerSets.getByName(layerName) != "undefined");

                    }catch(e){}

                 

                 

                    return hasProcessLayer;

                }

                 

                 

                // Get Layer ID

                function getActiveLayerId() {

                    var ref = new ActionReference();

                    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));

                    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

                    return executeActionGet(ref).getInteger( stringIDToTypeID( "layerID" ) );

                }

                 

                 

                // Activate Layer by ID

                function makeActiveByID( id ){

                    try{

                        var desc = new ActionDescriptor();

                            var ref = new ActionReference();

                            ref.putIdentifier( charIDToTypeID( "Lyr " ), id );

                        desc.putReference( charIDToTypeID( "null" ), ref );

                        desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                        executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

                        return activeDocument.activeLayer;

                    }catch(e){}

                    }

                1 person found this helpful