What I want to do is this:
1. Iterate through all the layers in a document (recursively) and discover each layer's NAME, VISIBLE, and LOCKED properties.
2. Create an object that contains those properties.
3. Push the object onto a second array.
4. Store that second array somewhere, preferably in a file (text?) in the same directory as the AI document.
5. Load that file at a later date as an object array.
6. Use the object array to iterate through the illustrator document to conform the current state of that document to the stored states in the array.
Ideally I would like to be able to store a number of separate states in the same document and refer to them somehow.
As you may have guessed by now, this is my attempt to make a LayerComps feature for Illustrator that I could use to turn visibilities on and off and then export the result, moving on from one state to the next until all the states I am interested in would be exported. I would settle for being able to do it one at a time.
I can already do steps 1-3 (shown in blue).
var doc = app.activeDocument;
var docName = doc.name;
var layerStates = [];
var layerCount = doc.layers.length;
var count = 0;
function addLayers(layerArray) {
for (var i=0; i<layerArray.length; i++) {
// create an object representing a layer state
var o = {};
o.name = layerArray[i].name;
o.visible = layerArray[i].visible;
o.locked = layerArray[i].locked;
layerStates[count] = o;
count++;
// if this layer has layers of its own, iterate through those
if (layerArray[i].layers.length > 0) {
addLayers(layerArray[i].layers);
}
}
}
addLayers(doc.layers);
// show that we did something, incomplete though it is
var s = "";
for (var i=0; i < layerStates.length; i++) {
s += layerStates[i].name + ": ";
s += (layerStates[i].visible ) ? "visible" : "invisible";
s += ", ";
s += (layerStates[i].locked ) ? "locked" : "unlocked";
s += "\n";
}
alert(s);
I don't know if it is possible to export that data as XML or even a text string and save it as a file on the file system for later parsing. Anyone have any thoughts about this? Is it possible?
Currently I am using a restrictive version of a LayerComps script I created, which iterates through a top layer's sublayers, turning each on and exporting as PDF, then turning it off and moving to the next. This is more convenient than doing it by hand, but it really forces me to compartmentalize all "views" of a document in a way that does not lend it self to efficiency and forces redundant copying of pathItems between layers.
Thoughts?