Hi, so i am trying to make a script that goes goes through all the layers of an a document, sets the size of the layer to a specified width and height and export it in a separate file. I finished the script but it really really slow. I read that accessing layers from the DOM is slow and that i should use the ActionManager instead, but I can't find any documentation on how to use the ActionManager.
This is what I have so far:
Ok so right now I am creating a document with the size I want. Copy the layer I want from the current doc to the new one and save the document. When I see a group I create a folder on the Directory and call the function recursively.
var refDoc; var tempDoc; function main(){ refDoc = app.activeDocument; tempDoc = app.documents.add(500, 500, 72, "tempDoc", NewDocumentMode.RGB, DocumentFill.TRANSPARENT); app.activeDocument = refDoc; mainFolder = app.activeDocument.path + "/test"; savetAllLayers(app.activeDocument, mainFolder); tempDoc.close (SaveOptions.DONOTSAVECHANGES); } function saveAllLayers(group, folderName){ var groupFolder = new Folder(folderName) for (var i = 0; i < group.layers.length; i++){ if (group.layers[i].typename.valueOf() === "LayerSet"){ var groupFolder = new Folder(folderName + "/" + group.layers[i].name); if (!groupFolder.exist){ groupFolder.create(); } saveAllLayers(group.layers[i], groupFolder); } else if (group.layers[i].typename.valueOf() === "ArtLayer"){ try { app.activeDocument = refDoc; group.layers[i].copy(); app.activeDocument = tempDoc; var targetLayer = tempDoc.artLayers.add(); tempDoc.paste(); tempDoc.activeLayer.resize(500, 500); var options = new ExportOptionsSaveForWeb(); options.fomat = SaveDocumentType.PNG; options.PNG8 = false; options.transparency = true; options.optimized = true; //Export Save for Web in the current folder tempDoc.exportDocument(File(folderName +'/' + group.layers[i].name +'.png'), ExportType.SAVEFORWEB, options); targetLayer.remove(); } catch (e){ alert("Error on layer: " + group.layers[i].name + "\n\n\n" + e.message); } } } return }}
How can I use the ActionManager to achieve this? Thank you.