Saturday, April 16, 2011

Save Layer States

OK, here's a really quick shot at saving layer states.

The script doesn't track by layer name, so if you add or remove a layer between uses, your layer visibility will be shifted. Fortunately, I'm using a simple system of 1's and 0's to track visibility, so you can easily edit the saved values if you added or removed a layer between runs.

Another limitation/caveat: This version doesn't look at sub-layers, just top level layers.

Someone who know how to write plugins should probably write something like this, but until then, if you're dying for a layer "save state" script, this should get you started.

Just run the script posted below and a prompt will come up with a bunch of ones and zeros in the text entry field. These represent the visibility of each root layer in your document. If you want to save your layer state, just manually copy the prompt data to a text document for use later.

When you want to reset your visibility to an older saved state, just rerun the script, and paste your saved string back into the prompt window, (erasing the existing data) and your layers will return to the original visibility settings.

Enjoy, and if you have any suggestions, requests or improvements, please email me, or post in the comments below.

var doc = activeDocument;

var binArr=[];
var i = 0;

for(var d=doc.layers.length-1;d>=0;d--)
        i= doc.layers[d].visible ? 1:0;

var p=prompt("Copy values to store layer visibility states, paste new data below to change.",binArr.join(""));

if (p!=null)
    binArr = p.split("");
    for(var d=binArr.length-1;d>=0;d--)
            if(doc.layers.length  > d){
                doc.layers[d].visible  = binArr[d] ==    0   ?  false : true;


Ben said...


thx a lot man! searched just for that!

If you have some time work further on the subvisibilitys ;)

keep it up!

John said...

Hey Ben, thanks for posting.

I agree it's an attractive idea. I'm just not sure it should be written as a script.

I currently don't see a way to save complex layer states without leaving a permanent mark on the document or garbling the layer visibility states after significant change. I'll think about it some more, and see if I can find a workaround.

Chris Fullmer said...

Photoshop does it perfectly fine. I'm sure its do-able. I use all the time in photoshop, and I miss it sorely in Illustrator.