-
Notifications
You must be signed in to change notification settings - Fork 0
/
Android-Export-Assets.jsx
106 lines (96 loc) · 3.33 KB
/
Android-Export-Assets.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Yair Carreno @yaircarreno ([email protected])
* Thanks to: @herkulano (http://www.herkulano.com)
*/
alert( "Por favor a continuacion seleccione la carpeta destino" );
var folder = Folder.selectDialog();
var document = app.activeDocument;
if (document && folder) {
var documentName = document.name;
var documentNameWithoutExtension = nameWithoutExtension(documentName);
var nameProject = prompt("Enter the name of your project", "") || "";
var rootFile = folder.absoluteURI + "/" + nameProject + "/";
var foldersAssets = document.width < 48 ? "drawable-" : "mipmap-";
saveToRes(100, foldersAssets + "mdpi", true);
saveToRes(150, foldersAssets + "hdpi", true);
saveToRes(200, foldersAssets + "xhdpi", true);
saveToRes(300, foldersAssets + "xxhdpi", true);
saveToRes(400, foldersAssets + "xxxhdpi", true);
//Guarda el proyecto como SVG
exportFileToSVG(rootFile + documentName);
//Guarda el proyecto en formato AI
exportFileToAI(rootFile + documentName);
alert( "Exportados los iconos notifications a : " + rootFile);
} else {
alert( "El directorio seleccionado es invalido");
}
/**
* Guarda los png.
*/
function saveToRes(scaleTo, folderName, lowerCase) {
var i, ab, file, options;
var myFolder = new Folder(rootFile + folderName);
if(!myFolder.exists) myFolder.create();
for (i = document.artboards.length - 1; i >= 0; i--) {
document.artboards.setActiveArtboardIndex(i);
ab = document.artboards[i];
var fileName = ab.name;
if(lowerCase){
var fileNameLowerCase = "";
for (var j = 0; j < fileName.length; j++) {
if(isUpperCase(fileName.charAt(j))){
if(j > 0){
fileNameLowerCase += "_";
}
fileNameLowerCase += fileName.charAt(j).toLowerCase();
}
else{
fileNameLowerCase += fileName.charAt(j);
}
}
fileName = fileNameLowerCase;
}
file = new File(myFolder.fsName + "/" + documentNameWithoutExtension + ".png");
options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = false;
options.verticalScale = scaleTo;
options.horizontalScale = scaleTo;
document.exportFile(file, ExportType.PNG24, options);
}
}
// Transforma todo a minuscula.
function isUpperCase(myString) {
return (myString == myString.toUpperCase());
}
//Elimina la extension del nombre del documento.
function nameWithoutExtension(myName) {
var finalDotPosition = myName.lastIndexOf( "." );
if ( finalDotPosition > -1 ) {
return myName.substr( 0 , finalDotPosition );
}
return myName;
}
// Guarda el proyecto en formato SVG para integrar con Android Studio Vector Assets.
function exportFileToSVG (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsSVG();
var type = ExportType.SVG;
var fileSpec = new File(dest);
exportOptions.embedRasterImages = true;
exportOptions.embedAllFonts = false;
exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}
//Guarda el proyecto Illustrator en formato AI.
function exportFileToAI (dest) {
if ( app.documents.length > 0 ) {
var saveOptions = new IllustratorSaveOptions();
var ai8Doc = new File(dest);
saveOptions.compatibility = Compatibility.ILLUSTRATOR8;
saveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
app.activeDocument.saveAs( ai8Doc, saveOptions );
}
}