-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportLayerSets.jsx
67 lines (54 loc) · 1.75 KB
/
exportLayerSets.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<javascriptresource>
<name>Color Scripts: Export Top-level Layer Sets</name>
<about>
This will export top level.
Layer-sets. It will ignore folders named "_REF_".
AND it requires folders to have masks.
</about>
<category>Viera</category>
<enableinfo>true</enableinfo>
</javascriptresource>
#include "vieraLibrary.jsx"
app.displayDialogs = DialogModes.NO;
var doc = app.activeDocument;
var docRef;
// Set compresisong settings for PNG
var pngSaveOptions = new PNGSaveOptions( );
pngSaveOptions.compression = 2;
var refLayer = new RegExp( /_REF_/gim );
var docName = new String( doc.name );
docName = docName.slice( 0 , -4 );
// Set path for export, and create folder if it doesn't exist.
var outputPngPath = new Folder( doc.path + "/PNG/" + docName + "/" );
if ( !outputPngPath.exists ) outputPngPath.create( );
for ( var i = doc.layers.length - 1; i >= 0; i-- )
{
if ( doc.layers[ i ].typename == "LayerSet" )
{
if ( !doc.layers[ i ].name.match( refLayer ) )
{
doc.activeLayer = doc.layers[ i ];
if ( !hasLayerMask( ) )
{
alert( "LayerSet Requires Mask" );
}
else
{
layerMaskToSelection( );
var grpName = new String( doc.layers[ i ].name );
grpName = grpName.slice( 3 );
var outputPngFile = new File( outputPngPath + "/" + docName +
grpName + ".png" );
doc.selection.copy( true );
var w = doc.selection.bounds[ 2 ];
var h = doc.selection.bounds[ 3 ];
docRef = app.documents.add( w, h );
docRef.paste( );
docRef.trim( TrimType.TOPLEFT, true, true, true, true );
docRef.trim( TrimType.BOTTOMRIGHT, true, true, true, true );
docRef.saveAs( outputPngFile, pngSaveOptions, true, Extension.LOWERCASE );
docRef.close( SaveOptions.DONOTSAVECHANGES );
}
}
}
}