Skip to main content
Inspiring
October 11, 2019
Answered

Script to set active layers pulled from .txt doc on desktop?

  • October 11, 2019
  • 18 replies
  • 3228 views

Hello,

  I'd like to be able to select layers based off a .txt file located on the desktop. So the text file would have a list of names it would index, which the script would read and index, then select any matching layer names in the open photoshop document. Is this possible to script via java? Thanks in advance. 

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

This one will delete the smart objects:

#target photoshop
var firstSnpStart = 1 // 1= first snapshot other than opening of file. 0 = open file snapshot
var doc = activeDocument;
var hsObj = doc.historyStates;
var hsLength = hsObj.length;
var snpNum = 0
var firstSnp, lastSnp

getFirstSnapshot ();
getLastSnapshot ();

if(firstSnp != lastSnp){
    doc.activeHistoryState = firstSnp;
    var useListFirst = [];
    var layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListFirst = getLayerSetsData();  

    for (var i=0;i<layerListFirst.length;i++){
        if(layerListFirst.type != 13){useListFirst.push(layerListFirst[i].id)};
        } //end for loop to get original layers   
    doc.activeHistoryState = lastSnp;
    var useListLast = [];
    layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListLast = getLayerSetsData();   
    
            for (var i=0;i<layerListLast.length;i++){
                if(layerListLast[i].type != 13&&layerListLast[i].type != 5){
                    var layerOk = true;
                    for(var j=0;j<useListFirst.length;j++){
                        if(layerListLast[i].id == useListFirst[j]){
                            layerOk = false;
                            }
                        }//enf j loop   
                    if(layerOk){useListLast.push(layerListLast[i].id)}
                   }//end if for layer type
                } //end i loop       
    multiSelectByIDs (useListLast)       
    }//end if to run script
else{alert('There are not two snapshots')}


function getLastSnapshot()
{
   for (var i=hsLength - 1;i>-1;i--)
   {
      if(hsObj[i].snapshot) {
          lastSnp = hsObj[i]
         break;
      }      
   }      
}

function getFirstSnapshot()
{
   for (var i=firstSnpStart;i<hsLength;i++)
   {
      if(hsObj[i].snapshot) {
         firstSnp = hsObj[i];
         break;
      }      
   }      
}

function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

function getLayerSetsData()
{
    //var count = 0;//set counter for multi-dimensional array
    var lyrSets = [];

    while (true)
    {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layerSets);
        try
            {var d1 = executeActionGet(ref)}
        catch (err){
            break;
            };

        var c2t = function (s){return app.charIDToTypeID(s);};
        var s2t = function (s){return app.stringIDToTypeID(s);};
        var lyrSet = {};

        lyrSet.type = d1.getInteger(s2t("layerKind"));
        lyrSet.name = d1.getString(c2t("Nm  "));
        lyrSet.id = d1.getInteger(s2t("layerID"));
        
        lyrSets.push(lyrSet);
        layerSets++;
    }; 
    return lyrSets;
};

 

 

18 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
October 18, 2019

This one will delete the smart objects:

#target photoshop
var firstSnpStart = 1 // 1= first snapshot other than opening of file. 0 = open file snapshot
var doc = activeDocument;
var hsObj = doc.historyStates;
var hsLength = hsObj.length;
var snpNum = 0
var firstSnp, lastSnp

getFirstSnapshot ();
getLastSnapshot ();

if(firstSnp != lastSnp){
    doc.activeHistoryState = firstSnp;
    var useListFirst = [];
    var layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListFirst = getLayerSetsData();  

    for (var i=0;i<layerListFirst.length;i++){
        if(layerListFirst.type != 13){useListFirst.push(layerListFirst[i].id)};
        } //end for loop to get original layers   
    doc.activeHistoryState = lastSnp;
    var useListLast = [];
    layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListLast = getLayerSetsData();   
    
            for (var i=0;i<layerListLast.length;i++){
                if(layerListLast[i].type != 13&&layerListLast[i].type != 5){
                    var layerOk = true;
                    for(var j=0;j<useListFirst.length;j++){
                        if(layerListLast[i].id == useListFirst[j]){
                            layerOk = false;
                            }
                        }//enf j loop   
                    if(layerOk){useListLast.push(layerListLast[i].id)}
                   }//end if for layer type
                } //end i loop       
    multiSelectByIDs (useListLast)       
    }//end if to run script
else{alert('There are not two snapshots')}


function getLastSnapshot()
{
   for (var i=hsLength - 1;i>-1;i--)
   {
      if(hsObj[i].snapshot) {
          lastSnp = hsObj[i]
         break;
      }      
   }      
}

function getFirstSnapshot()
{
   for (var i=firstSnpStart;i<hsLength;i++)
   {
      if(hsObj[i].snapshot) {
         firstSnp = hsObj[i];
         break;
      }      
   }      
}

function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

function getLayerSetsData()
{
    //var count = 0;//set counter for multi-dimensional array
    var lyrSets = [];

    while (true)
    {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layerSets);
        try
            {var d1 = executeActionGet(ref)}
        catch (err){
            break;
            };

        var c2t = function (s){return app.charIDToTypeID(s);};
        var s2t = function (s){return app.stringIDToTypeID(s);};
        var lyrSet = {};

        lyrSet.type = d1.getInteger(s2t("layerKind"));
        lyrSet.name = d1.getString(c2t("Nm  "));
        lyrSet.id = d1.getInteger(s2t("layerID"));
        
        lyrSets.push(lyrSet);
        layerSets++;
    }; 
    return lyrSets;
};

 

 

Inspiring
October 18, 2019

Hi chuck, 

    This actually deletes the smart objects from the file, I only want to deselect them from the actively selected layers. I basically want all newly generated layers, except for smart objects, to be selected. 

Chuck Uebele
Community Expert
Community Expert
October 18, 2019

I re-edited my last reply to use the correct script. I didn't notice that it selected SO that were new. Just needed to change the "||" to "&&".

Chuck Uebele
Community Expert
Community Expert
October 17, 2019

One more time. Hopefully, this will be it. You can set this to either use the open file state as the first snapshot or the first manually set snapshot as a reference. To do so, you have to change the variable firstSnpStart to either 0, which will use the document open state as the first snapshot, or 1 for the first manually set snapshot. Other than making sure you set a second ending snapshot, there nothing else to do, other than run the script.

 

 

#target photoshop
var firstSnpStart = 1 // 1= first snapshot other than opening of file. 0 = open file snapshot
var doc = activeDocument;
var hsObj = doc.historyStates;
var hsLength = hsObj.length;
var snpNum = 0
var firstSnp, lastSnp

getFirstSnapshot ();
getLastSnapshot ();

if(firstSnp != lastSnp){
    doc.activeHistoryState = firstSnp;
    var useListFirst = [];
    var layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListFirst = getLayerSetsData();  

    for (var i=0;i<layerListFirst.length;i++){
        if(layerListFirst.type != 13){useListFirst.push(layerListFirst[i].id)};
        } //end for loop to get original layers   
    doc.activeHistoryState = lastSnp;
    var useListLast = [];
    layerSets = 0
    try{doc.backgroundLayer}
    catch(e){layerSets=1}
    var layerListLast = getLayerSetsData();   
    
            for (var i=0;i<layerListLast.length;i++){
                if(layerListLast[i].type != 13||layerListLast[i].type != 5){
                    var layerOk = true;
                    for(var j=0;j<useListFirst.length;j++){
                        if(layerListLast[i].id == useListFirst[j]){
                            layerOk = false;
                            }
                        }//enf j loop   
                    if(layerOk){useListLast.push(layerListLast[i].id)}
                   }//end if for layer type
                } //end i loop         
    multiSelectByIDs (useListLast)       
    }//end if to run script
else{alert('There are not two snapshots')}


function getLastSnapshot()
{
   for (var i=hsLength - 1;i>-1;i--)
   {
      if(hsObj[i].snapshot) {
          lastSnp = hsObj[i]
         break;
      }      
   }      
}

function getFirstSnapshot()
{
   for (var i=firstSnpStart;i<hsLength;i++)
   {
      if(hsObj[i].snapshot) {
         firstSnp = hsObj[i];
         break;
      }      
   }      
}

function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

function getLayerSetsData()
{
    //var count = 0;//set counter for multi-dimensional array
    var lyrSets = [];

    while (true)
    {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layerSets);
        try
            {var d1 = executeActionGet(ref)}
        catch (err){
            break;
            };

        var c2t = function (s){return app.charIDToTypeID(s);};
        var s2t = function (s){return app.stringIDToTypeID(s);};
        var lyrSet = {};

        lyrSet.type = d1.getInteger(s2t("layerKind"));
        lyrSet.name = d1.getString(c2t("Nm  "));
        lyrSet.id = d1.getInteger(s2t("layerID"));
        
        lyrSets.push(lyrSet);
        layerSets++;
    }; 
    return lyrSets;
};
Inspiring
October 18, 2019

Amazing! It works Great! And its fast. The only addition that would make it perfect, would be if it could remove all smart objects from the selected layers at the end, both linked and embedded. But if thats not possible or if you don't want to contiue on this script, I totally understand! Thank you for yall your help!

Chuck Uebele
Community Expert
Community Expert
October 16, 2019

I did find out why it's not saving the info to the text file: your file doesn't have a background layer. Have to change the code to check for that.

Inspiring
October 16, 2019
That is correct: my file doesn't not contain a locked "Background" layer.
Chuck Uebele
Community Expert
Community Expert
October 16, 2019
That's an easy fix. Trying to figure out how to get the snapshots
Chuck Uebele
Community Expert
Community Expert
October 16, 2019

Well, let's see what I can come up with.

Chuck Uebele
Community Expert
Community Expert
October 16, 2019

Opps, it was the 3rd one that doesn't write. The second one should. 

Chuck Uebele
Community Expert
Community Expert
October 16, 2019

The way I wrote the script,  the second function doesn't write to the text file. It just reads it from where you set it to capture all the layers before editing, then uses that info to select the new layers. Yes it could be written just to use history states. At that point,  would you even need the text file? What would you want to store on it, if you still want it?

Inspiring
October 16, 2019
If it can be done without the text file, that would be great! I know array's of information can be built, just wasn't sure if the arrays hold across history states. The only thing th array should return is layer IDs in this case, from the first history state, and cross referenced against the most current history state to make our selection of all new layers, minus smart objects. We would not need any .txt file in this case
Chuck Uebele
Community Expert
Community Expert
October 16, 2019

Try this. I used an old write routine that works for me. So I swapped it out with one that you provided, that seemed to work for you.

#target photoshop
var txtFile = new File('~/desktop/Text for scripts/select layers.txt');
var doc = activeDocument;
var method = 0

var dlg = new Window('dialog','Get, Save, and Inver layer selection');
dlg.getLay = dlg.add('button',undefined,'Select Layers from Text File');
dlg.saveLay = dlg.add('button',undefined,'Save all Layers to text File');
dlg.getNew = dlg.add('button',undefined,'Select New Layers that are not in the Text File');

dlg.getLay.onClick = function(){
    method = 1;
    dlg.close();
    }
dlg.saveLay.onClick = function(){
    method = 2;
    dlg.close();
    }
dlg.getNew.onClick = function(){
    method = 3;
    dlg.close();
    }

dlg.show();

switch(method){
    case 1:
        if(txtFile.exists){
            var layerList = readFile (txtFile).split('\n');    
            multiSelectByIDs (layerList)   
            }
        else{alert('There is no text file')};
        break;
    case 2:
        var useList = '';
        var layerList = getLayerSetsData();
        for (var i=0;i<layerList.length;i++){
            if(layerList.type != 13){useList +=layerList[i].id +'\n'};
            }
        writeFile (txtFile, useList);
        break;
    case 3:

        if(txtFile.exists){
            var layerListOld = readFile (txtFile).split('\n');    
            var layerList = getLayerSetsData();
            var layerListNew = new Array();
            for (var i=0;i<layerList.length;i++){
                if(layerList[i].type != 13||layerList[i].type != 5){
                    var layerOk = true;
                    for(var j=0;j<layerListOld.length;j++){
                        if(layerList[i].id == layerListOld[j]){
                            layerOk = false;
                            }
                        }//enf j loop   
                    if(layerOk){layerListNew.push(layerList[i].id)}
                   }//end if for layer type
                } //end i loop
            multiSelectByIDs (layerListNew)
            }//end if text exists
        else{alert('There is no text file')};
        break;        
    }//end switch


function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

function getLayerSetsData()
{
    //var count = 0;//set counter for multi-dimensional array
    var lyrSets = [];
    var layerSets = 0;
    while (true)
    {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layerSets);
        try
            {var d1 = executeActionGet(ref)}
        catch (err){
            break;
            };

        var c2t = function (s){return app.charIDToTypeID(s);};
        var s2t = function (s){return app.stringIDToTypeID(s);};
        var lyrSet = {};

        lyrSet.type = d1.getInteger(s2t("layerKind"));
        lyrSet.name = d1.getString(c2t("Nm  "));
        lyrSet.id = d1.getInteger(s2t("layerID"));
        
        lyrSets.push(lyrSet);
        layerSets++;
    }; 
    return lyrSets;
};

//===============READ/WRITE functions========================================
//=========================================================================
 function readFile(file) {
	if (!file.exists) {
		alert( "Cannot find file: " + deodeURI(file.absoluteURI));
		}
	else{
		file.encoding = "UTF8";
		file.lineFeed = "unix";
		file.open("r", "TEXT", "????");
		var str = file.read();
		file.close();

		return str;
		};
};

// Export to txt file
function writeFile(file,str) {
    // Detect line feed type
    if ( $.os.search(/windows/i) !== -1 ) {
    fileLineFeed = "Windows";
    }
    else {
    fileLineFeed = "Macintosh";
    }    
    try {
    file.remove();
    file.open('a');
    file.lineFeed = fileLineFeed;
    file.write(str);
    file.close();
    }
    catch(e){}
}
Inspiring
October 16, 2019

Hi Chuck,

  The second function still creates an empty .txt. file. Also can we remove the dialog all together and have it just step back to the first history state, record and write out all the layer IDs, then go back to most recent history state via Snapshot, and read in that .txt and select all new layers, minus smart objects, all in one fell swoop? Below is the code that worked for presenting a dialog of all selected layer IDs. How to get that written out in a .txt file is the next part. Thaks again,

 

-M

Chuck Uebele
Community Expert
Community Expert
October 16, 2019

I'll have to look at my script again. I was working okay on my end. What OS are you using?

Inspiring
October 16, 2019
Im on MacOS
Chuck Uebele
Community Expert
Community Expert
October 16, 2019
Ok, I'm on Win, so there might be some issue there. Let me look into this.
Chuck Uebele
Community Expert
Community Expert
October 15, 2019

One more time. I combined all the scripts into one with a UI that you select what you want to do.

The first button will select all layers that is in the text file. Actually, looking at your workflow, you might not need that.

The second button will record all existing layers to the text file. So either before you start editing, or go to your previous history state, run this to record all the layers.

The last button will recall the layers in the text file (old) and compare them to the current state. It will select all added layers, except smart objects, that were added after the recording of the layers to the text file.

Again, edit the path and name of the text file to your use.

#target photoshop
var txtFile = new File('~/desktop/Text for scripts/select layers.txt');
var doc = activeDocument;
var method = 0

var dlg = new Window('dialog','Get, Save, and Inver layer selection');
dlg.getLay = dlg.add('button',undefined,'Select Layers from Text File');
dlg.saveLay = dlg.add('button',undefined,'Save all Layers to text File');
dlg.getNew = dlg.add('button',undefined,'Select New Layers that are not in the Text File');

dlg.getLay.onClick = function(){
    method = 1;
    dlg.close();
    }
dlg.saveLay.onClick = function(){
    method = 2;
    dlg.close();
    }
dlg.getNew.onClick = function(){
    method = 3;
    dlg.close();
    }

dlg.show();

switch(method){
    case 1:
        if(txtFile.exists){
            var layerList = readFile (txtFile).split('\n');    
            multiSelectByIDs (layerList)   
            }
        else{alert('There is no text file')};
        break;
    case 2:
        var useList = '';
        var layerList = getLayerSetsData();
        for (var i=0;i<layerList.length;i++){
            if(layerList.type != 13){useList +=layerList[i].id +'\n'};
            }
        writeFile (txtFile, useList);
        break;
    case 3:

        if(txtFile.exists){
            var layerListOld = readFile (txtFile).split('\n');    
            var layerList = getLayerSetsData();
            var layerListNew = new Array();
            for (var i=0;i<layerList.length;i++){
                if(layerList[i].type != 13||layerList[i].type != 5){
                    var layerOk = true;
                    for(var j=0;j<layerListOld.length;j++){
                        if(layerList[i].id == layerListOld[j]){
                            layerOk = false;
                            }
                        }//enf j loop   
                    if(layerOk){layerListNew.push(layerList[i].id)}
                   }//end if for layer type
                } //end i loop
            multiSelectByIDs (layerListNew)
            }//end if text exists
        else{alert('There is no text file')};
        break;        
    }//end switch


function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

function getLayerSetsData()
{
    //var count = 0;//set counter for multi-dimensional array
    var lyrSets = [];
    var layerSets = 0;
    while (true)
    {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layerSets);
        try
            {var d1 = executeActionGet(ref)}
        catch (err){
            break;
            };

        var c2t = function (s){return app.charIDToTypeID(s);};
        var s2t = function (s){return app.stringIDToTypeID(s);};
        var lyrSet = {};

        lyrSet.type = d1.getInteger(s2t("layerKind"));
        lyrSet.name = d1.getString(c2t("Nm  "));
        lyrSet.id = d1.getInteger(s2t("layerID"));
        
        lyrSets.push(lyrSet);
        layerSets++;
    }; 
    return lyrSets;
};

//===============READ/WRITE functions========================================
//=========================================================================
 function readFile(file) {
	if (!file.exists) {
		alert( "Cannot find file: " + deodeURI(file.absoluteURI));
		}
	else{
		file.encoding = "UTF8";
		file.lineFeed = "unix";
		file.open("r", "TEXT", "????");
		var str = file.read();
		file.close();

		return str;
		};
};

function writeFile(file,str) {
		file.encoding = "UTF8";
		file.open("w", "TEXT", "????");
		//unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF"
		file.write("\uFEFF");
		file.lineFeed = "unix";
		file.write(str);
		file.close();
		
	};
 //=========================================================================
Inspiring
October 15, 2019

Hey Chuck,

    When I run the script and use the second option to save all layers to .txt file, it runs and saves a text file out, but that text file doesn't contain anything, its empty. When I then run the script again and select the third option to select New Layers not in text file, it breaks and throws this error message:

 

 

So I don't know if this would make it more simple or not, but it would be better for my workflow if there is no dialogue at all, and the script would first create a snapshot named "Ready for R# update", then go back to first history state and select all layers and write out the .txt file of selected layer ids to desktop, then immediately reverts back to the snapshot named "Ready for R# update" and selects all new layers (minus smart objects) read in from that .txt file. Let me know how that sounds. Thank you for your continued effort. 

Inspiring
October 16, 2019
I was able to find this, which when all layers are selected, will show you all the layer IDs. Maybe this will help?
Chuck Uebele
Community Expert
Community Expert
October 14, 2019

I will have to rework the code. It should run a lot faster though.

Inspiring
October 14, 2019
Nice.....I really appreciate all the help!