Skip to main content
Participant
August 9, 2016
Answered

Converting snapshots to layers

  • August 9, 2016
  • 4 replies
  • 872 views

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...

This topic has been closed for replies.
Correct answer Chuck Uebele

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 replies

c.pfaffenbichler
Community Expert
Community Expert
August 15, 2016

// 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;

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[0];

  app.activeDocument = thisCopy;

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

  thisCopy.close(SaveOptions.DONOTSAVECHANGES);

  theNewLayer.name = "snapshot_"+theSnaps[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"))

};

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
August 9, 2016

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.

DanykwebAuthor
Participant
August 9, 2016

Allow non-linear! Thanks!

c.pfaffenbichler
Community Expert
Community Expert
August 9, 2016

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

pixxxelschubser
Community Expert
Community Expert
August 9, 2016

For the beginning:

alert(activeDocument.historyStates.length);

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

Have fun