Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save itfrombit/821502 to your computer and use it in GitHub Desktop.
Save itfrombit/821502 to your computer and use it in GitHub Desktop.
var path = "/Users/jsb/Desktop/LayerTest";
var filename = "jefftest.acorn";
var acorn = JSTalk.application("Acorn");
var doc = acorn.open(path + "/" + filename);
var count = doc.layers().count();
for (i = 0; i < count; i++)
{
doc.layers()[i].visible = NO;
}
for (i = 0; i < count; i++)
{
if (i > 0)
doc.layers()[i-1].visible = NO;
doc.layers()[i].visible = YES;
doc.dataOfType("public.png").writeToFile(path + "/layer" + i + ".png");
}
doc.close();
@haikusw
Copy link

haikusw commented Feb 12, 2011

Is there any reason to duplicate the document for each layer? seems the tmpDoc.duplicate() and tmpDoc.close could go outside the outer loop. I don't have time to try this at the moment but wondered... you set them visible/invisible each time through the loop... ?

I have a similar script that uses the names of the layers as the names of the output files which is handy for some cases.

@itfrombit
Copy link
Author

No, that was just sloppy code. You don't actually have to duplicate the document at all. Here's an updated version that's a little cleaner.

@haikusw
Copy link

haikusw commented Feb 13, 2011

ok!. wondered about that. thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment