Can I use ExtendScript to store info about an Illustrator document externally and recover it later?

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?

Also good, and thanks again for your help. I wasn't sure if ExtendScript implemented the eval() method, necessary to re-objectify a JSON string, because I can't find it in the documentation, but I do see it used in some examples elsewhere. I've successfully written XML files at this point, and when I get a few minutes I'll work on the reading/modifying/exporting part. In the long run, XML files are easier to read, manipulate and maintain, so I'll probably go that route.
var doc = app.activeDocument;
var docName = doc.name;
var xml = new XML("<root></root>");
var layerStates = [];
var layerCount = doc.layers.length;
var count = 0;
function addLayers(layerArray, xmlObj) {
    for (var i=0; i<layerArray.length; i++) {
        // create an object representing a layer state
        var lay = layerArray[i];
        var x = new XML("<layer/>");
        x.@name = lay.name;
        x.@visible = lay.visible;
        x.@locked = lay.locked;
        xmlObj.appendChild(x);
        layerStates[count] = x.toXMLString();
        count++;
        // if this layer has layers of its own, iterate through those
        if (lay.layers.length > 0) {
            addLayers(lay.layers, x);
addLayers(doc.layers, xml);
var xmlFile = new File();
xmlFile.open('w');
xmlFile.write(xml);
xmlFile.copy ('C:/Program Files (x86)/Adobe/Adobe Illustrator CS4/Presets/en_US/Scripts/data.xml');
xmlFile.close();
All in all, the documentation for this stuff leaves a little something to be desired. My original question had more to do with how file read and write text streams was handled. The answer was actually much simpler than I anticipated. All this stuff is, once you get a handle on it, but the docs are so stingy on particulars — does it really help us to know about the XML class merely that it "wraps XML into an object" or that XML.attribute(name) "returns a list containing all attribute elements matching the given name"? I finally worked it out for myself that the XML object may be manipulated using dot syntax (x.name, x.@name), but that was certainly not mentioned anywhere.
Ah, well. The journey is the reward, right?

Similar Messages

  • Is there another way of getting apps from the appstore without putting your credit card number in, ive heard about the itunes gift card thing can anybody just give me more info about that and how i can buy free things free things from the appstorepls help

    Is there another way of getting apps from the appstore without putting your credit card number in, ive heard about the itunes gift card thing can anybody just give me more info about that and how i can buy free things free things from the appstore...pls help as im only a teenager and have no credit credit and my parents dont trust me with theres and they dont care about the fact that you can set up a password/.... PLEASE SOMEONE HELP I WILL BE SO GRATEFUL... And i would really like to get the iphone 4 but if there is no way of etting apps without your credit number then i would have to get a samsung galaxy s3 maybe ...

    You can set up an Apple ID without a credit card.
    Create iTunes Store account without credit card - Support - Apple - http://support.apple.com/kb/ht2534

  • Can i use the same payment info on more than one iphone?

    Can i use the same payment info on more than one iphone?

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    Accepted forms of payment  >  http://support.apple.com/kb/HT5552

  • How can I programmably extract the project build information set in the project build specification. So I can then use the information in an 'About' dialog.

    Extracting Project information
    How can I programmably extract the project build information set in the project build specification.
    So I can then use the information in an ‘About’ dialog.
    Dave

    In the labview\resource\appbuild folder their are some VI's that can deal with build specs! They return a variant containing the data!
    It's the reason I build a variant probe.
    Be aware that the build info is not present in th lvproj file of the built executable!
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Why i can't use apple app store with my apple id?

    Dear All,
    why i can't use apple app store with my apple id?
    but I don't have Credit Card.My Country doesn't support.
    My Country is included in Apple OS X (10.9.2) but not in the billing.
    How could I download even free apps from Apple Apps store without using credit info?
    becoz I want to fill these brackets but iTune say me to fill it how can I?.........  
                                                                               Best Regards,
                                                                                destar77

    http://support.apple.com/kb/ht2534

  • Can i use OER to store the data from a excel sheet that pertains to the entire integrations ?

    hi ,
    i know that the OER can be used to view the entire landscape for the SOA composites and how they are related with each other. However we have a requirement wherein we need to store the data for the entire integration end systems e.g. ebiz, mfgpro, siebel etc ( that is we need to store data one level up).
    Also,  we want a customized form in OER wherein user can manually add data regarding the integrations.
    So is it possible to do so ? If yes, how ?

    ok, let me put it this way,
    I tried using the import/export utility available under OER admin tab.
    When i export my existing assets it generates the .xml file for each asset. Now as i have hundreds on new assets to be created for each asset type i want to be able to create a new .xml file and want it to create the new asset once i import it using import utility. I tried creating a new .xml file giving it a new UUID but it does not seem to work. Has anyone tried this earlier who can give the steps to do this ?

  • I changed the name of my apple id and now I can't use the app store on my phone correctly because it's using my apple id's old name. I signed out and in on itunes and synced my iphone. Still doesn't work. Help please?

    I changed the name of my apple id and now I can't use the app store on my phone correctly because it's using my apple id's old name. I signed out and in on itunes and synced my iphone. Still doesn't work. Help please?

    Settings>Store...tap the ID shown...sign out...sign back in with the ID you want to use.
    Note: Apps are forever tied to the Apple ID used to originally obtain them. They cannot be updated using any other Apple ID other than the one they were originally obtained with.

  • Can I use multiple Apple store gift cards per transaction or is it has to be one gift card per transaction?

    Can I use multiple Apple store gift cards (£25 each) per transaction or is it has to be only one gift card per transaction?? Does anyone know thanks

    Hola, Eddy
    notice that you have posted to an old thread (Oct-Nov2013) that actually took quite some time to get attention back then**
    I recommend that you contact the Store Group regarding your purchase question - don't let the "iTune-ish" URL and page title throw you off... it's the right place
    Store Group - Contact Us - Apple Support
    ** next time you have a question, I advise to check the dates carefully and if older than a month or so, AND it has no answer to your specific issue, start a NEW Question. You did a fine job of stating your exact issue - many folks, not so much.
    buenos dias
    CCC

  • How can i reset my app store setting? i have signed in and out with my own apple id but i used a different one at first and that one is not going away

    How can i reset my app store setting?
    I have signed in and out with my own apple id but i used a different one at first a few years ago and that one is not going away how do i change it to my own apple id?

    Content and Apple IDs -
    Content is forever tied to the Apple ID that bought it. Apple does not transfer content from one Apple ID to another. Apple does not merge Apple IDs. You will never be able to access your content bought with one Apple ID with a new Apple ID. Your only option is to delete the content and buy it again with the new Apple ID.

  • Can I use icloud to store my iTunes library music in order to free up storage/usage space on my iPhone?

    Can I use icloud to store my iTunes music library in order to free up usage space on my iPhone and iPad?

    iTunes match is a true streaming service when it comes to playback from your PC. That means, you can load everything into the cloud and stream from the cloud to your PC.
    To an iPhone or iPad, it's stream-and-save, meaning it will download and play immediately, but it will be saved to the device.
    So yes, you can load everything up (assuming it all loads properly without problems) and stream to your PC.

  • Can I use ICloud to store all my data and use it seamlessly with my devices and Mac?

    Can I use ICloud to store all my data and use it seamlessly with my devices and Mac.  I.E. I want to use it as I use my time capsule and get rid of all this stuff I have in my office.

    Yes.
    Apple - iCloud - Learn how to set up iCloud on all your devices

  • Can you use the us store in the philippines

    can you use the us store in the philippines

    No, in order to use a country's store you need a valid billing address in that country and be in that country when purchasing from it. If it's music that you are interested in then are there other music purchase download sites that you could use ? You can also copy your own CDs via your computer's iTunes

  • HT2534 I have apple ID with out Visa card but I can't use to Tunis store please help me to open Tunis with out Visa card

    I need to download Facebook YouTube and Google search on my screen with all the programs I have apple ID but when I ask to load it say that this apple ID is not known by Tunis store so please I open my ID with out Visa card so as to use Tunis store with out Visa card because I am poor to have Visa card please help me soon!!! Thanks for your kind immediately support !!!!

    If you follow, exactly, the instructions on the HT2534 page that you posted from when creating a new account (the instructions won't work with existing accounts) then you will get the 'none' option - I tried it earlier today on both my computer's iTunes and iPhone and I got 'none' for new accounts on both. If you don't use those instructions then credit card details will need to be entered before the account can be used in the store.
    using a computer : https://discussions.apple.com/message/24321860
    using an iPhone : https://discussions.apple.com/message/24700173
    If you want to try using the same email address on a new account then you will need to replace it on that one first e.g. via the Store > View Account menu option on your computer's iTunes or http://appleid.apple.com

  • Daughter has used iPad for her Apple account and I can't use the App store because her username automatically shows up in the Apple ID window.  How do I change that?

    My daughter has used our iPad for her Apple account and now I can't use the App store because her username automatically shows up in the Apple ID window.  How do I change that so I can put our Apple ID in with the appropriate Password?

    Open Settings -> Store
    Tap on the Apple ID shown and sign out. Then sign in with your own Apple ID.
    Update: Oops, AnaMusic was faster...

  • I do not have a credit card how can I use the App Store from Belize

    I do not have a credit card how can I use the App Store from Belize

    iTunes gift cards.

Maybe you are looking for

  • LR4 and Camera Raw 6.7

    Hello, This is my first post, so please bear with me if I do something wrong. I got LR4 (update from 3) right after it was relesed.  I also have Photoshop CS5, so I ran into the PS/LR4 interoperability issue like everybody else.  I just checked the s

  • BADI creation

    Hi, I want to create a BADI in ECC6.0 version of sap.. Can any one let me know the step by step procedure for it and please let me know the significance of Enhancement Spot . Please let me know how to attach newly created BADI in standard SAP source

  • Has anyone had a SD card melt while in the SD card slot in a mac book pro?

    I own a MacBook Pro, from Mid 2012, (owned it for about a year, brand new) up-to-date software and have never had any problems with my MacBook until I recently tried to put an SD card into my SD card slot. I tried to see if I could see if there was a

  • Mail.app 3.0

    Greetings, I run a postfix server looking after a couple of domains. Myself and a number of people use the server on a daily basis to send and receive a large volume of email, the client of choice currently being Entourage 2004, (fully patched), thou

  • Wacom Intuos + Yosemite = Freeze

    Just as an FYI to those of you having issues with Wacom Intuos tablets and Yosemite. There is definitely an issue causing lockups/freezing with the Wacom drivers under Yosemite. This is also being discussed over at MacRumors. My combo is: Retina iMac