5 Replies Latest reply on Aug 15, 2016 4:39 AM by c.pfaffenbichler

    Converting snapshots to layers

    Danykweb

      My query is specifically about how to do what is stated in the subject. I've wracked my brain trying to figure a way to do this in an efficient way. The closest I've been able to figure is to step through layers and copy them into a new doc and then copy them back but this requires knowing how many snapshots there are in the original doc. What I'm looking for is to take all of the history snapshot states (regardless of the amount of snapshots) and convert them into individual layers in the original document.

       

      Is it possible to script a solution that looks in history for anything named "snapshot" and somehow outputs the history states as multiple layers into the source document? If so, how would you go about doing this?

       

      Thank you to anyone that can help with this. I know little to nothing about scripting...

        • 1. Re: Converting snapshots to layers
          pixxxel schubser MVP & Adobe Community Professional

          For the beginning:

          alert(activeDocument.historyStates.length);
          alert(activeDocument.historyStates[0].snapshot); // if true, it's a snapshot
          

           

          Have fun

           

          • 2. Re: Converting snapshots to layers
            c.pfaffenbichler Level 9

            I would recommend making flattened copies of the image at the various Snapshots and then collecting those as Layers into the original file.

            • 3. Re: Converting snapshots to layers
              Chuck Uebele Adobe Community Professional & MVP

              I would also suggest making a flattened copy and saving as a layer by using merged stamp visible. To keep the flattened layers, you might have to either set your history state to nonlinear or save the flattened layer to a new doc while you create them.

              • 4. Re: Converting snapshots to layers
                Danykweb Level 1

                Allow non-linear! Thanks!

                • 5. Re: Converting snapshots to layers
                  c.pfaffenbichler Level 9

                  // 2016, use it at your own risk;

                  #target photoshop

                  if (app.documents.length > 0) {

                  var myDocument = app.activeDocument;

                  var thisHist = myDocument.activeHistoryState;

                  var theHist = myDocument.historyStates;

                  var theSnaps = new Array;

                  // create docs;

                  for (var m = 0; m < theHist.length; m++) {

                  var thisOne = theHist[m];

                  if (thisOne.snapshot == true) {

                    myDocument.activeHistoryState = thisOne;

                    var theName = thisOne.name;

                    var theDup = duplicateImage (theName, true);

                    theSnaps.push([activeDocument, theName, theDup]);

                    app.activeDocument = myDocument;

                    myDocument.activeHistoryState = thisHist;

                    }

                  };

                  // duplicate layers;

                  for (var n = 0; n < theSnaps.length; n++) {

                    var thisCopy = theSnaps[n][0];

                    app.activeDocument = thisCopy;

                    var theNewLayer = activeDocument.layers[0].duplicate(myDocument, ElementPlacement.PLACEATBEGINNING);

                    thisCopy.close(SaveOptions.DONOTSAVECHANGES);

                    theNewLayer.name = "snapshot_"+theSnaps[n][1]

                    };

                  };

                  ////// duplicate image //////

                  function duplicateImage (theName, merged) {

                  // =======================================================

                  var idDplc = charIDToTypeID( "Dplc" );

                      var desc8 = new ActionDescriptor();

                      var idnull = charIDToTypeID( "null" );

                          var ref7 = new ActionReference();

                          var idDcmn = charIDToTypeID( "Dcmn" );

                          var idOrdn = charIDToTypeID( "Ordn" );

                          var idFrst = charIDToTypeID( "Frst" );

                          ref7.putEnumerated( idDcmn, idOrdn, idFrst );

                      desc8.putReference( idnull, ref7 );

                      var idNm = charIDToTypeID( "Nm  " );

                      desc8.putString( idNm, theName );

                      var idMrgd = charIDToTypeID( "Mrgd" );

                      desc8.putBoolean( idMrgd, merged );

                  var theResult = executeAction( idDplc, desc8, DialogModes.NO );

                  // get doc ID;

                  var ref = new ActionReference();

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

                  var docDesc = executeActionGet(ref);

                  return docDesc.getInteger(stringIDToTypeID("documentID"))

                  };

                  2 people found this helpful