• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to Export Layers as PNG maintaining Artboard dimension

New Here ,
Jun 03, 2020 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);
}

 

TOPICS
Import and export , Scripting

Views

1.1K

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
community guidelines

correct answers 2 Correct answers

Community Expert , Jun 03, 2020 Jun 03, 2020

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

Votes

Translate

Translate
New Here , Jun 04, 2020 Jun 04, 2020

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.D
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 03, 2020 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

Votes

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
community guidelines
Community Expert ,
Jun 03, 2020 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

Votes

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
community guidelines
New Here ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

LATEST

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..

Votes

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
community guidelines