Highlighted

Script to Export Layers as PNG maintaining Artboard dimension

New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

Artboard 1

->layer 1

->layer 2

 

finding a script to export layer 1 and 2 as png with dimension of Artboard 1.

tried this one, it worked but exported layers sizes are diffrent..

var options = new ExportOptionsPNG24();
var doc = app.activeDocument;
$.writeln("trying to save");

var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height);
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect;

saveSubLayers(doc, "");

newdoc.close(SaveOptions.DONOTSAVECHANGES);

function saveSubLayers(node, path){
    for (var i=0; i<node.layers.length; i++){
        var layer = node.layers[i];
        if (!layer.visible) 
                continue;
        if (layer.layers.length > 0){
             saveSubLayers(layer, path+"/"+layer.name);
        } else {
            saveLayer(layer, path);
        }        
    }
}

function saveLayer(layer, path){
    newdoc.layers[0].remove();
    var newlayer = newdoc.layers[0];
	for (var ii = layer.pageItems.length - 1; ii >= 0; ii--)
		layer.pageItems[ii].duplicate(newlayer, ElementPlacement.PLACEATBEGINNING);

	new Folder(doc.path + path).create();
	newdoc.exportFile(new File(doc.path + path + "/" + layer.name + ".png"), ExportType.PNG24, options);
}

 

Adobe Community Professional
Correct answer by Scott Falkner | Adobe Community Professional

I don’t know sweet FA about scripting, but I did spring for Smart Layer Export. It's very customizable and versatile.

https://exchange.adobe.com/creativecloud.details.2955.smart-layer-export.html

 

There’s also a free version. Less versatile and customizable, but perhaps better suited to your situation.

https://gist.github.com/TomByrne/7816376

TOPICS
How to, Import and export, Scripting

Views

366

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script to Export Layers as PNG maintaining Artboard dimension

New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

Artboard 1

->layer 1

->layer 2

 

finding a script to export layer 1 and 2 as png with dimension of Artboard 1.

tried this one, it worked but exported layers sizes are diffrent..

var options = new ExportOptionsPNG24();
var doc = app.activeDocument;
$.writeln("trying to save");

var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height);
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect;

saveSubLayers(doc, "");

newdoc.close(SaveOptions.DONOTSAVECHANGES);

function saveSubLayers(node, path){
    for (var i=0; i<node.layers.length; i++){
        var layer = node.layers[i];
        if (!layer.visible) 
                continue;
        if (layer.layers.length > 0){
             saveSubLayers(layer, path+"/"+layer.name);
        } else {
            saveLayer(layer, path);
        }        
    }
}

function saveLayer(layer, path){
    newdoc.layers[0].remove();
    var newlayer = newdoc.layers[0];
	for (var ii = layer.pageItems.length - 1; ii >= 0; ii--)
		layer.pageItems[ii].duplicate(newlayer, ElementPlacement.PLACEATBEGINNING);

	new Folder(doc.path + path).create();
	newdoc.exportFile(new File(doc.path + path + "/" + layer.name + ".png"), ExportType.PNG24, options);
}

 

Adobe Community Professional
Correct answer by Scott Falkner | Adobe Community Professional

I don’t know sweet FA about scripting, but I did spring for Smart Layer Export. It's very customizable and versatile.

https://exchange.adobe.com/creativecloud.details.2955.smart-layer-export.html

 

There’s also a free version. Less versatile and customizable, but perhaps better suited to your situation.

https://gist.github.com/TomByrne/7816376

TOPICS
How to, Import and export, Scripting

Views

367

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

I don’t know sweet FA about scripting, but I did spring for Smart Layer Export. It's very customizable and versatile.

https://exchange.adobe.com/creativecloud.details.2955.smart-layer-export.html

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

I don’t know sweet FA about scripting, but I did spring for Smart Layer Export. It's very customizable and versatile.

https://exchange.adobe.com/creativecloud.details.2955.smart-layer-export.html

 

There’s also a free version. Less versatile and customizable, but perhaps better suited to your situation.

https://gist.github.com/TomByrne/7816376

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 03, 2020 1
New Here ,
Jun 04, 2020

Copy link to clipboard

Copied

https://gist.github.com/TomByrne/7816376

this one worked like a charm,

but i've figured out missing parameters from existing script and that also worked fine,

var options = new ExportOptionsPNG24();
options.artBoardClipping = true; //this line

var doc = app.activeDocument;
$.writeln("trying to save");

var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height);
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect;


saveSubLayers(doc, "");

newdoc.close(SaveOptions.DONOTSAVECHANGES);

function saveSubLayers(node, path){
    for (var i=0; i<node.layers.length; i++){
        var layer = node.layers[i];
        if (!layer.visible) 
                continue;
        if (layer.layers.length > 0){
             saveSubLayers(layer, path+"/"+layer.name);
        } else {
            saveLayer(layer, path);
        }        
    }
}


function saveLayer(layer, path){
    newdoc.layers[0].remove();
    var newlayer = newdoc.layers[0];
	for (var ii = layer.pageItems.length - 1; ii >= 0; ii--)
		layer.pageItems[ii].duplicate(newlayer, ElementPlacement.PLACEATBEGINNING);

	new Folder(doc.path + path).create();
	newdoc.exportFile(new File(doc.path + path + "/" + layer.name + ".png"), ExportType.PNG24, options);
}

 but again github one has more control over exported content so yeah, gotta use that.. thanks for helping me out..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 04, 2020 0