Hello. I need a .jsx script that do the following...
- Take all visible layers and save them as separate .png files in a new folder. The names of the files should be the same as the names of the layers.
Would somebody help me write this script ? thanks for a FANTASTIC forum !!!!!
Need script that export only visible layers to new folder
-
pfaffenbichler
Need script that export only visible layers to new folder
Well, what have you got so far?
How complex is the Layer structure? Would visible Layers in invisible Groups be an issue?
How complex is the Layer structure? Would visible Layers in invisible Groups be an issue?
-
DanielR
Need script that export only visible layers to new folder
No groups, only plain named layers where some is visible and others invisible. The script should prompt a name for the folder, and then put all the visible layers in this folder as files named after the names of the layers.
Would this be possible you think ?
Would this be possible you think ?
-
pfaffenbichler
Need script that export only visible layers to new folder
Certainly possible.
Have you checked out Paul’s Layer Saver
http://www.scriptsrus.talktalk.net/Layer%20Saver.htm
yet?
Have you checked out Paul’s Layer Saver
http://www.scriptsrus.talktalk.net/Layer%20Saver.htm
yet?
-
DanielR
Need script that export only visible layers to new folder
I checked it, but it does not export only visible layers (selected layers can be exported), and not to new folders.
the script I need should simply just export visible layers only, to a user set folder, but also create a new folder in the user set folder (the new folder name should be prompted and set by user) in which to put the layers as .png files with transparency. the name of the files should be the name of the layers.
is this possible to do you think ?
Thank you
the script I need should simply just export visible layers only, to a user set folder, but also create a new folder in the user set folder (the new folder name should be prompted and set by user) in which to put the layers as .png files with transparency. the name of the files should be the name of the layers.
is this possible to do you think ?
Thank you
-
pfaffenbichler
Need script that export only visible layers to new folder
It is possible.
Which steps do pose problems to you?
Which steps do pose problems to you?
-
DanielR
Need script that export only visible layers to new folder
Im not a coder, so I pretty much need help with all of it. I found a script that maybe can be modified for the purpose...
http://www.kirupa.com/motiongraphics/scripting6_2.htm
http://www.kirupa.com/motiongraphics/scripting6_2.htm
-
pfaffenbichler
Need script that export only visible layers to new folder
Far from elegant, but you could give this a try.
You should be able to achieve the creation of the new Folder from the Folder selection dialog.
Code: Select all// 2012, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
// select folder;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
var theLayers = collectVisibleLayers(myDocument, []);
// create a history state;
myDocument.quickMaskMode = true;
myDocument.quickMaskMode = false;
var theState = myDocument.activeHistoryState;
// process the visible layers;
for (var m = 0; m < theLayers.length; m++) {
myDocument.artLayers.add();
var theLayer = theLayers[m];
hideOthers (theLayer, myDocument);
deleteHiddenLayers ();
savePNG (myDocument, theFolder, theLayer.name)
myDocument.activeHistoryState = theState;
};
}
};
////// function to png //////
function savePNG (myDocument, docPath, basename) {
// weboptions;
var webOptions = new ExportOptionsSaveForWeb();
webOptions.format = SaveDocumentType.PNG;
webOptions.PNG8 = false;
webOptions.transparency = true;
webOptions.interlaced = 0;
webOptions.includeProfile = false;
webOptions.optimized = true;
myDocument.exportDocument(new File(docPath+"/"+basename+".png"), ExportType.SAVEFORWEB, webOptions);
};
////// function collect all layers //////
function collectVisibleLayers (theParent, allLayers) {
if (!allLayers) {var allLayers = new Array}
else {};
for (var m = theParent.layers.length - 1; m >= 0;m--) {
var theLayer = theParent.layers[m];
if (theLayer.typename == "ArtLayer") {
if (theLayer.visible == true) {
allLayers.push(theLayer)
}
}
// apply the function to layersets;
else {
allLayers = (collectVisibleLayers(theLayer, allLayers))
}
};
return allLayers
};
////// delete hidden layers //////
function deleteHiddenLayers () {
try {
var id26 = charIDToTypeID( "Dlt " );
var desc6 = new ActionDescriptor();
var id27 = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var id28 = charIDToTypeID( "Lyr " );
var id29 = charIDToTypeID( "Ordn" );
var id30 = stringIDToTypeID( "hidden" );
ref6.putEnumerated( id28, id29, id30 );
desc6.putReference( id27, ref6 );
executeAction( id26, desc6, DialogModes.NO );
} catch (e) {}
};
////// toggle visibility of others //////
function hideOthers (theLayer, myDocument) {
myDocument.activeLayer = theLayer;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list4 = new ActionList();
var ref7 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref7.putEnumerated( idLyr, idOrdn, idTrgt );
list4.putReference( ref7 );
desc10.putList( idnull, list4 );
var idTglO = charIDToTypeID( "TglO" );
desc10.putBoolean( idTglO, true );
executeAction( idShw, desc10, DialogModes.NO );
};
You should be able to achieve the creation of the new Folder from the Folder selection dialog.
Code: Select all// 2012, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
// select folder;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
var theLayers = collectVisibleLayers(myDocument, []);
// create a history state;
myDocument.quickMaskMode = true;
myDocument.quickMaskMode = false;
var theState = myDocument.activeHistoryState;
// process the visible layers;
for (var m = 0; m < theLayers.length; m++) {
myDocument.artLayers.add();
var theLayer = theLayers[m];
hideOthers (theLayer, myDocument);
deleteHiddenLayers ();
savePNG (myDocument, theFolder, theLayer.name)
myDocument.activeHistoryState = theState;
};
}
};
////// function to png //////
function savePNG (myDocument, docPath, basename) {
// weboptions;
var webOptions = new ExportOptionsSaveForWeb();
webOptions.format = SaveDocumentType.PNG;
webOptions.PNG8 = false;
webOptions.transparency = true;
webOptions.interlaced = 0;
webOptions.includeProfile = false;
webOptions.optimized = true;
myDocument.exportDocument(new File(docPath+"/"+basename+".png"), ExportType.SAVEFORWEB, webOptions);
};
////// function collect all layers //////
function collectVisibleLayers (theParent, allLayers) {
if (!allLayers) {var allLayers = new Array}
else {};
for (var m = theParent.layers.length - 1; m >= 0;m--) {
var theLayer = theParent.layers[m];
if (theLayer.typename == "ArtLayer") {
if (theLayer.visible == true) {
allLayers.push(theLayer)
}
}
// apply the function to layersets;
else {
allLayers = (collectVisibleLayers(theLayer, allLayers))
}
};
return allLayers
};
////// delete hidden layers //////
function deleteHiddenLayers () {
try {
var id26 = charIDToTypeID( "Dlt " );
var desc6 = new ActionDescriptor();
var id27 = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var id28 = charIDToTypeID( "Lyr " );
var id29 = charIDToTypeID( "Ordn" );
var id30 = stringIDToTypeID( "hidden" );
ref6.putEnumerated( id28, id29, id30 );
desc6.putReference( id27, ref6 );
executeAction( id26, desc6, DialogModes.NO );
} catch (e) {}
};
////// toggle visibility of others //////
function hideOthers (theLayer, myDocument) {
myDocument.activeLayer = theLayer;
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list4 = new ActionList();
var ref7 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref7.putEnumerated( idLyr, idOrdn, idTrgt );
list4.putReference( ref7 );
desc10.putList( idnull, list4 );
var idTglO = charIDToTypeID( "TglO" );
desc10.putBoolean( idTglO, true );
executeAction( idShw, desc10, DialogModes.NO );
};
-
DanielR
Need script that export only visible layers to new folder
Thank you.. I will try it, but the script should not delete any layers or change visibility, only save visible layers to separate folder.
Thanks
Thanks
-
pfaffenbichler
Need script that export only visible layers to new folder
but the script should not delete any layers or change visibility, only save visible layers to separate folder.
So?
So?