Created
August 15, 2016 16:35
-
-
Save amolok/073c8a2e0c5dda14b7dd3acca79802f7 to your computer and use it in GitHub Desktop.
Junior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target Illustrator | |
/* | |
bgr.png | |
bgrTop.png | |
maskY.png | |
pole_p.png | |
tablo.png | |
stat / downALL3.bmp | |
*/ | |
// app.scriptPreferences.enableRedraw = true; | |
d = app.activeDocument; | |
a = d.artboards; | |
l = d.layers; | |
// ЭКСПОРТ | |
var filePath = d.path; | |
var exportPath = '/Source/'; | |
var sname = '/scripts/make Junior nbors.jsx'; | |
// ЭКСПОРТ в PNG | |
var exportOptions = new ExportOptionsPNG24(); | |
var type = ExportType.PNG24; | |
exportOptions.artBoardClipping = true; | |
exportOptions.antiAliasing = true; | |
exportOptions.transparency = true; | |
exportOptions.saveAsHTML = false; | |
// AntiAliasingMethod.ARTOPTIMIZED | |
// для слива статистики в одну картинку | |
var docPreset = new DocumentPreset; | |
docPreset.units = RulerUnits.Pixels; | |
docPreset.title = 'stat'; | |
// var rectRef = newDoc.pathItems.rectangle(770, 10, 500, 750); | |
var zeroMode = '0'; | |
var zeroLayers = new Array; | |
zeroLayers = ['pole-','Top-','nbors','MaskY-']; | |
coloredLayers = new Array; | |
coloredLayers = ['Top-0','Top-00','bgr','tablo','stat']; | |
var colors = new Array; | |
// colors = ['PINK', 'VIOLETTE', 'ORANGE', 'GREEN', 'BORDO', 'BLUE']; | |
// { | |
// var cl = l.getByName('bgr').groupItems; | |
// for (var i = 0; i < cl.length; i++) { | |
// colors.push(cl[i].name); | |
// }; | |
// } | |
var Junior = { | |
modes: ['Betty', 'Junior'], | |
mode: '', | |
colors: ['VIOLETTE', 'ORANGE', 'GREEN', 'BORDO', 'BLUE'], | |
zeroMode: '0', | |
zeroLayers: ['pole-','Top-','nbors-','MaskY-'], | |
coloredLayers: ['Top-0','Top-00','bgr'], | |
// coloredLayers: ['Top-0','Top-00','bgr-0','bgr-00'], | |
// states: ['bgr', 'bgrTop', 'stat', 'pole_p', 'tablo', 'maskY'], | |
state: '', | |
states: { | |
'0': { | |
// 'bgr': ['Mesh', 'tablo', /*'stat', */ 'pole-0', 'bgr-0'], | |
'bgr': ['Mesh', 'tablo', 'stat', 'pole-0', 'bgr', 'Logo'], | |
// 'bgrTop': ['Mesh', 'tablo', 'stat', 'pole-0', 'bgr-0', 'Top-0'], | |
'bgrTop': ['Mesh', 'tablo', 'stat', 'pole-0', 'bgr', 'Top-0', 'Logo'], | |
'pole_p': [/*'pole-'+t.zeroMode*/], | |
'tablo': [/*'tablo'*/], | |
// 'stat': ['Mesh', 'tablo', 'stat', 'bgr-0'], | |
'stat': ['Mesh', 'tablo', 'stat', 'bgr'], | |
'maskY': ['maskY-0'], | |
}, | |
'00': { | |
// 'bgr': ['Mesh', 'tablo', /*'stat', */ 'pole-00', 'bgr-00'], | |
'bgr': ['Mesh', 'tablo', 'stat', 'pole-00', 'bgr', 'Logo'], | |
// 'bgrTop': ['Mesh', 'tablo', /*'stat', */ 'pole-00', 'bgr-00', 'Top-00'], | |
'bgrTop': ['Mesh', 'tablo', 'stat', 'pole-00', 'bgr', 'Top-00', 'Logo'], | |
'pole_p': [/*'pole-'+t.zeroMode*/], | |
'tablo': [/*'tablo'*/], | |
// 'stat': ['Mesh', 'tablo', 'stat', 'bgr-00'], | |
'stat': ['Mesh', 'tablo', 'stat', 'bgr'], | |
'maskY': ['maskY-00'], | |
} | |
}, | |
stats: ['even-odd', 'red-black', '1-18-19-36'], | |
debug: 2, | |
redraw: true, | |
l: app.activeDocument.layers, | |
getColors: function() | |
{ | |
var t = this; | |
t.colors = []; | |
// var cl = l.getByName('bgr-0').groupItems; | |
var cl = l.getByName('bgr').groupItems; | |
for (var i = 0; i < cl.length; i++) { | |
t.colors.push(cl[i].name); | |
}; | |
t.colors.sort(); | |
}, | |
clean: function(){ | |
var t = this; | |
for (var i = 0; i < Junior.l.length; i++) { | |
Junior.l[i].visible = false; | |
}; | |
if(t.debug)$.writeln('Junior.clean '+t.state); | |
t.state = ''; | |
}, | |
layerShow: function(lname,show){ | |
var t = this; | |
if(t.debug>1)$.writeln('Junior.layerShow( '+lname+' : '+show+' ):'); | |
try{ | |
Junior.l.getByName(lname).visible = show; | |
}catch(err){ | |
$.writeln('Junior.layerShow( '+lname+', '+show+' ) --- '+err.message); | |
} | |
}, | |
subLayerShow: function(player,lname,show){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.subLayerShow( '+player+' / '+lname+' : '+show+' ):'); | |
try{ | |
Junior.l.getByName(player).layers.getByName(lname).visible = show; | |
}catch(err){ | |
if(t.debug)$.writeln('Junior.subLayerShow( '+player+' / '+lname+' : '+show+' ) --- '+err.message); | |
} | |
}, | |
groupShow: function(lname,gname,show){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.groupShow( '+lname+' / '+gname+' : '+show+' ):'); | |
try{ | |
Junior.l.getByName(lname).groupItems.getByName('gname').hidden = (show==false); | |
}catch(err){ | |
$.writeln('Junior.groupShow( '+lname+' / '+gname+' : '+show+') --- '+err.message); | |
} | |
}, | |
show: function(lname){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.show( '+lname+ ')'); | |
if (typeof lname == 'string'){ | |
t.layerShow(lname,true); | |
}else{ | |
for (var i = 0; i < lname.length; i++) { | |
t.layerShow(lname[i], true); | |
}; | |
}; | |
if(t.redraw) redraw(); | |
}, | |
switchZero: function(z){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.switchZero('+z+'): '+'zeroMode = '+t.zeroMode); | |
for (var i = 0; i < t.zeroLayers.length; i++) { | |
t.layerShow(t.zeroLayers[i]+'0', (z=='0') ? true : false ); | |
t.layerShow(t.zeroLayers[i]+'00', (z=='00') ? true : false ); | |
}; | |
t.zeroMode = z; | |
if(t.redraw) redraw(); | |
}, | |
init: function(){ | |
var t = this; | |
t.mode = d.name.split('.')[0]; | |
if(t.debug)$.writeln('mode: '+t.mode); | |
t.switchZero(t.zeroMode); | |
t.getColors(); | |
t.clean(); | |
a.setActiveArtboardIndex(0); | |
if(t.redraw) redraw(); | |
}, | |
switchColor: function(c){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.switchColor: '+c); | |
for (var i = 0; i < t.coloredLayers.length; i++) { | |
var cl = l.getByName(t.coloredLayers[i]).groupItems; | |
cl.parent.visible = true; | |
if(t.debug>1)$.writeln('.switchColor: '+t.coloredLayers[i]+' ('+cl.length+')'); | |
for (var j = 0; j < t.colors.length; j++) { | |
try{ | |
if(t.debug>1)$.writeln('.switchColor: '+t.colors[j]); | |
cl.getByName(t.colors[j]).hidden = (cl.getByName(t.colors[j]).name != c); | |
}catch(err){ | |
$.writeln('switchColor: '+t.coloredLayers[i]+' / '+t.colors[j] +' --- '+ err.message); | |
} | |
}; | |
}; | |
t.switchZero(t.zeroMode); | |
if(t.redraw) redraw(); | |
}, | |
switchState: function(state){ | |
var t = this; | |
t.clean(); | |
var showLayers = new Array; | |
if(t.debug) $.writeln('Junior.switchState('+state+'):'); | |
try{ | |
showLayers=t.states[t.zeroMode][state]; | |
}catch(err){ | |
$.writeln('Junior.switchState( '+state+' ) --- '+err.message); | |
} | |
t.show(showLayers); | |
t.state = state; | |
// t.switchZero(t.zeroMode); | |
if(state=='stat') t.switchStat('bg'); | |
if(t.redraw)redraw(); | |
}, | |
switchStat: function(stat){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.switchStat( '+stat+' ): '); | |
if(stat!='bg')t.switchState('stat'); | |
for (var i = 0; i < t.stats.length; i++) { | |
t.subLayerShow('stat', t.stats[i], (t.stats[i] == stat) ? true:false); | |
}; | |
if(t.redraw)redraw(); | |
}, | |
exportNeighbours: function(){ | |
var t = this; | |
if(t.debug)$.writeln('Junior.exportNeighbours:'); | |
var p = new ProgressBar("exportNeighbours:",350,100); | |
p.show("Initializing...", 2, 0); | |
p.hit(); | |
t.clean; | |
t.layerShow('nbors'+t.zeroMode,true); | |
setActiveArtboardByName('nbors-'+t.zeroMode); | |
p.hit('exporting'); | |
saveScene('nbors'); | |
var aiFile = File(filePath+exportPath+'nbors.png'); | |
var psScript = 'app.displayDialogs = DialogModes.NO;'; | |
// psScript += ''; | |
psScript += 'app.open(' + aiFile.toSource() + ');'; | |
psScript += '$.setenv("zeroes", "'+t.zeroMode+'");'; | |
psScript += '$.evalFile("'+filePath+sname+'");'; | |
// psScript += 'app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );'; | |
if(t.debug>1)$.writeln( psScript ); | |
p.hit('Open in PhotoShop'); | |
btMessaging( 'photoshop', psScript ); | |
function btMessaging( targetApp, script ) { | |
var bt = new BridgeTalk(); | |
bt.target = targetApp; | |
bt.body = script; | |
bt.onResult = function( inBT ) { p.hit('Photoshop -- success!'); }; | |
bt.onError = function( inBT ) { alert( 'So NOT Done…\nPlease check: '+filePath+sname+'!' ) }; | |
bt.send( 20 ); | |
}; | |
p.msg('exportNeighbours finished'); | |
$.sleep(500); | |
p.close(); | |
} | |
} | |
if (app.documents.length > 0){ | |
var t = new Date(); | |
$.writeln('\n================================================================= export Junior '+t.toLocaleTimeString()); | |
if (! (Folder(filePath+exportPath).exists) ){ | |
Folder(filePath+exportPath).create(); | |
} | |
Junior.init(); | |
win = new Window("dialog", "export Junior:"); | |
win.alignChildren = "fill"; | |
win.b = new Array; | |
win.b[0] = 0; | |
win.pZ = win.add('panel {text: "ZEROs:", margins: [10,10,10,10], orientation: "row" }'); | |
win.pC = win.add('panel {text: "switchColor:", margins: [5,10,5,10] }'); | |
win.pS = win.add('panel {text: "switchState:", margins: [5,10,5,10] }'); | |
win.p = win.add('panel {text: "export:", margins: [5,10,5,10] }'); | |
win.b['z'] = win.pZ.add('button {text: "«0»", bounds: [0,0,150,50]}'); | |
win.b['zz'] = win.pZ.add('button {text: "«00»", bounds: [0,0,150,50]}'); | |
win.b[0] = win.p.add('button {text: "Tablo — основная графика", bounds: [0,0,300,50]}'); | |
win.b[1] = win.p.add('button {text: "Stat — статистика", bounds: [0,0,300,50]}'); | |
win.b[2] = win.p.add('button {text: "Fonts — шрифты", bounds: [0,0,300,50]}'); | |
win.b[3] = win.p.add('button {text: "MaskY — разметка табло", bounds: [0,0,300,50]}'); | |
win.b[4] = win.p.add('button {text: "nbors — соседи", bounds: [0,0,300,50]}'); | |
// win.b[4] = win.p.add('button {text: "ProgressBar проверка", bounds: [0,0,300,50]}'); | |
// win.b[4] = win.p.add('button {text: "переключение цветов", bounds: [0,0,300,50]}'); | |
win.add('button',undefined,'Cancel'); | |
win.b['z'].onClick = function() { | |
// zeroMode='0'; | |
this.parent.text = 'ZERO'; | |
win.b['z'].enabled = false; | |
win.b['zz'].enabled = true; | |
// switchZero(zeroMode); | |
Junior.switchZero('0'); | |
} | |
win.b['zz'].onClick = function() { | |
this.parent.text = 'DOUBLE ZERO'; | |
// zeroMode='00'; | |
win.b['z'].enabled = true; | |
win.b['zz'].enabled = false; | |
// switchZero(zeroMode); | |
Junior.switchZero('00'); | |
} | |
win.b[0].onClick = function () {exportTablo();} | |
win.b[1].onClick = function () {exportStat(); flatternStat();} | |
win.b[2].onClick = function () {exportFonts();} | |
win.b[3].onClick = function () {exportMaskY();} | |
win.b[4].onClick = function () {Junior.exportNeighbours();} | |
win.pC.b = new Array; | |
var g; | |
for (var i = 0; i < Junior.colors.length; i++) { | |
/* if ((i%3 ==0) && i<3){ | |
win.pC.p = new Array; | |
win.pC.p[i] = win.pC.add | |
} | |
*/ | |
if( i%((Junior.colors.length<5) ? 2 : 3) == 0 ){g = win.pC.add('group');} | |
win.pC.b[i] = g.add('button {text: "'+Junior.colors[i]+'", bounds: [0,0,100,50]}'); | |
win.pC.b[i].onClick = function () { | |
Junior.switchColor(this.text); | |
} | |
}; | |
win.pS.b = new Array; | |
g =[]; | |
var i = 0; | |
for (var state in Junior.states[/*t.zeroMode*/'0']) { | |
if( (i++%3) == 0 ){g = win.pS.add('group');} | |
win.pS.b[i] = g.add('button {text: "'+state+'", bounds: [0,0,100,25]}'); | |
win.pS.b[i].onClick = function () { | |
Junior.switchState(this.text); | |
} | |
}; | |
g=[]; | |
for (var i = 0; i < Junior.stats.length; i++) { | |
if( (i%3) == 0 ){g = win.pS.add('group');} | |
win.pS.b[i] = g.add('button {text: "'+Junior.stats[i]+'", bounds: [0,0,100,25]}'); | |
win.pS.b[i].onClick = function () { | |
Junior.switchStat(this.text); | |
} | |
}; | |
/* | |
win.b[4].onClick = function () { | |
switchColor(colors[2]); | |
}*/ | |
/* win.b[4].onClick = function () { | |
var found = new Array (50); | |
var w = new Window ('palette'); | |
w.pbar = w.add('progressbar', undefined, 0, found.length); | |
w.t = w.add('statictext'); | |
w.pbar.preferredSize.width = 300; | |
w.t.text='progressbar'; | |
w.show(); | |
for (var i = 0; i < found.length; i++){ | |
w.pbar.value = i+1; | |
w.t.text=i; | |
w.update(); | |
redraw(); | |
$.sleep(20); | |
} | |
} | |
*/ | |
if(win.show()==1){ | |
// win.pZ.enabled = false; | |
// win.p.enabled = false; | |
// win.hide(); | |
win.close(); | |
}else{ | |
win.close(); | |
} | |
// exportTablo(); | |
// exportStat(); | |
// flatternStat(); | |
// exportFonts(); | |
// exportMaskY(); | |
$.writeln('================================================================= export Junior '+t.toLocaleTimeString()); | |
} | |
function exportMaskY(){ | |
$.writeln('--- exportMaskY:'); | |
var p = new ProgressBar("exportMaskY:",350,100); | |
var name = 'maskY'; | |
p.show("Initializing...", 2, 0); | |
p.hit(); | |
Junior.init(); | |
p.show("exporting MaskY", 2, 0); | |
Junior.show('MaskY-'+Junior.zeroMode); | |
p.hit(); | |
if(Junior.debug)$.writeln('exportMask: '+name); | |
var fileExport = new File(filePath+exportPath+name); | |
var exportMaskOptions = new ExportOptionsPNG8(); | |
if(Junior.debug>1)$.writeln('exportMask ExportOptionsPNG8 preparing'); | |
exportMaskOptions.antiAliasing = false; | |
exportMaskOptions.artBoardClipping = true; | |
exportMaskOptions.colorCount = 256; | |
exportMaskOptions.colorDither = ColorDitherMethod.NOREDUCTION; | |
exportMaskOptions.colorReduction = ColorReductionMethod.SELECTIVE; | |
exportMaskOptions.ditherPercent = 0; | |
exportMaskOptions.transparency = true; | |
exportMaskOptions.saveAsHTML = false; | |
if(Junior.debug>1)$.writeln('exportMask ExportOptionsPNG8 done'); | |
app.activeDocument.exportFile(fileExport, ExportType.PNG8, exportMaskOptions); | |
if(Junior.debug)$.writeln('exportMask exportFile: '+fileExport); | |
p.hit(); | |
if(Junior.debug)$.writeln('exportMask exportFile rotatePhotoShopPNG...'); | |
// rotatePhotoShopPNG('maskY',true,false); | |
p.hit(); | |
p.close(); | |
} | |
function saveZones(name){ | |
var exportZonesOptions = new ExportOptionsPNG24(); | |
var type = ExportType.PNG24; | |
exportZonesOptions.artBoardClipping = true; | |
exportZonesOptions.antiAliasing = false; | |
exportZonesOptions.transparency = false; | |
exportZonesOptions.saveAsHTML = false; | |
var rasterizeOptions = new RasterizeOptions(); | |
rasterizeOptions.antiAliasingMethod = AntiAliasingMethod.None; | |
rasterizeOptions.backgroundBlack = true; | |
rasterizeOptions.clippingMask = false; | |
rasterizeOptions.resolution = 72.0; | |
rasterizeOptions.transparency = false; | |
rasterizeOptions.convertSpotColors = true; | |
var fileExport = new File(filePath+exportPath+name); | |
var t = d.layers.add(); | |
t.name = 'tmp '+name; | |
var tmpGroup = t.groupItems.add(); | |
array = []; | |
process(z); | |
for (var i = array.length-1; i>=0; i--) { | |
if( ! array[i].parent.locked ) { | |
tmpSel = array[i].duplicate(); | |
}else{ | |
array[i].parent.locked = false; | |
tmpSel = array[i].duplicate(); | |
} | |
tmpSel.moveToBeginning(tmpGroup); | |
}; | |
tmpRast = d.rasterize(tmpGroup, d.artboardRect, rasterizeOptions); | |
$.writeln('saveZones: '+filePath+exportPath+name); | |
app.activeDocument.exportFile( fileExport, type, exportZonesOptions ); | |
// app.Undo(); | |
tmpRast.remove(); | |
// tmpGroup.remove(); | |
// t.visible=false; | |
t.remove(); | |
} | |
function exportTablo(){ | |
$.writeln('--- exportTablo:'); | |
var p = new ProgressBar("exportTablo:",350,100); | |
p.show("Initializing...", 2, 0); | |
p.hit(); | |
Junior.init(); | |
p.show('saveScene:', 4, 1); | |
p.hit('bgr'); | |
Junior.switchState('bgr'); | |
saveScene('bgr'); | |
rotatePhotoShopPNG('bgr'); | |
Junior.switchState('bgrTop'); | |
p.hit('bgrTop'); | |
saveScene('bgrTop'); | |
rotatePhotoShopPNG('bgrTop'); | |
p.hit('pole_p'); | |
Junior.switchState('pole_p'); | |
saveScene('pole_p'); | |
rotatePhotoShopPNG('pole_p'); | |
p.hit('tablo'); | |
Junior.switchState('tablo'); | |
saveScene('tablo'); | |
rotatePhotoShopPNG('tablo'); | |
p.msg('exportTablo finished'); | |
Junior.switchZero(Junior.zeroMode); | |
Junior.switchState('bgrTop'); | |
$.sleep(500); | |
p.close(); | |
} | |
function exportStat(){ | |
$.writeln('--- exportStat:'); | |
var p = new ProgressBar("exportStat:",350,100); | |
p.show("Preparing Layers...", 5, 0); | |
Junior.init(); | |
Junior.switchState('stat'); | |
Junior.switchStat(''); | |
p.hit('stat3'); | |
exportSlice('stat', 'stat3'); | |
for (var i = 0; i < Junior.stats.length; i++) { | |
Junior.switchStat(Junior.stats[i]); | |
if(Junior.debug)$.writeln('exportStat: '+Junior.stats[i]); | |
p.hit(Junior.stats[i]); | |
exportSlice('stat', 'stat'+i); | |
}; | |
p.msg('exportStat finished'); | |
$.sleep(500); | |
p.close(); | |
} | |
function flatternStat(){ | |
$.writeln('flatternStat'); | |
var p = new ProgressBar("flatternStat:",350,100); | |
p.show("Preparing...", 5, 0); | |
var s = l.getByName('Slices').pathItems.getByName('stat'); | |
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM; | |
docPreset.width = s.width * 4; | |
docPreset.height = s.height; | |
var newDoc = app.documents.addDocument(DocumentColorSpace.RGB,docPreset); | |
newDoc.activate(); | |
newDoc.artboards.setActiveArtboardIndex(0); | |
var r = newDoc.artboards[0].artboardRect; | |
for (var i = 0; i < 4; i++) { | |
var item = app.activeDocument.placedItems.add(); | |
var name = 'stat'+i+'.png'; | |
var file = new File(filePath+exportPath+name); | |
item.file = file; | |
item.left = item.width * i - r[0]; | |
item.position[1] = 0; | |
$.writeln('flatternStat: '+ filePath + exportPath + name +" @ "+ item.left); | |
p.hit('flatternStat: '+name); | |
}; | |
p.hit('saveScene: stat'); | |
saveScene('stat'); | |
newDoc.close(SaveOptions.DONOTSAVECHANGES); | |
var aiFile = File(filePath+exportPath+'stat.png'); | |
var psScript = 'app.displayDialogs = DialogModes.NO;'; | |
psScript += 'app.open(' + aiFile.toSource() + ');'; | |
psScript += 'app.activeDocument.resizeImage( undefined,undefined,72,ResampleMethod.NONE);'; | |
psScript += 'app.activeDocument.rotateCanvas( -90 );'; | |
psScript += 'var exportOptions = new BMPSaveOptions();'; | |
psScript += 'exportOptions.alphaChannels = false;'; | |
psScript += 'exportOptions.depth = BMPDepthType.TWENTYFOUR;'; | |
psScript += 'var file = new File("'+d.path+exportPath+'stat.bmp");'; | |
// psScript += ''; | |
psScript += 'app.activeDocument.saveAs(file, exportOptions, true, Extension.LOWERCASE);'; | |
// psScript += 'app.activeDocument.close( SaveOptions.DONTSAVECHANGES );'; | |
psScript += 'app.activeDocument.close( SaveOptions.SAVECHANGES );'; | |
psScript += 'app.displayDialogs = DialogModes.ALL;'; | |
//$.writeln( psScript ); | |
p.hit('open in photoshop'); | |
btMessaging( 'photoshop', psScript ); | |
function btMessaging( targetApp, script ) { | |
var bt = new BridgeTalk(); | |
bt.target = targetApp; | |
bt.body = script; | |
bt.onResult = function( inBT ) { p.hit('Photoshop -- success!'); }; | |
bt.onError = function( inBT ) { alert( 'NOT Done…' ) }; | |
bt.send( 20 ); | |
}; | |
p.msg('flatternStat finished'); | |
$.sleep(500); | |
p.close(); | |
} | |
function exportFonts(){ | |
$.writeln('--- exportFonts:'); | |
var p = new ProgressBar("exportFonts:",350,100); | |
p.show('exportFonts...',a.length,0); | |
var ab = new Array(); | |
l.getByName('FNT').visible = true; | |
for (var i = 0; i < a.length; i++) { | |
var str = a[i].name; | |
// $.writeln(str); | |
// $.writeln(str.indexOf('font')); | |
if (str.indexOf('font') != -1) {ab.push(str);} | |
} | |
$.writeln('artboard fonts: '+ab.length); | |
for (var i = 0; i < ab.length; i++) { | |
setActiveArtboardByName(ab[i]); | |
var name = ab[i].split(': ')[1]; | |
p.hit(name); | |
saveScene(name); | |
rotatePhotoShopPNG(name,true,true); | |
}; | |
p.close(); | |
} | |
function saveScene(name){ | |
var fileExport = new File(filePath+exportPath+name); | |
$.writeln('saveScene: '+name); | |
app.activeDocument.exportFile(fileExport, type, exportOptions); | |
// $.sleep(500); | |
} | |
function exportSlice(slice, name){ | |
a.setActiveArtboardIndex(0); | |
var s = l.getByName('Slices'); | |
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM; // ARTBOARDCOORDINATESYSTEM; | |
dRect = new Array; | |
for (var i = 0; i < d.artboards[0].artboardRect.length; i++) { | |
dRect.push(d.artboards[0].artboardRect[i]); | |
}; | |
s.visible = true; | |
s.locked = false; | |
p = s.pathItems; | |
try{ | |
d.selection = []; | |
p.getByName(slice).selected = true; | |
d.fitArtboardToSelectedArt(0); | |
$.writeln('exportSlice: '+slice); | |
saveScene(name); | |
}catch(err){ | |
alert(eRect.join(', ')+'\t ('+dRect.join(', ')+')'+'\n'+err.message,'exportSlice: '+ slice +" to "+ name); | |
} | |
s.visible = false; | |
d.artboards[0].artboardRect = dRect; | |
} | |
function ProgressBar(/*str*/title, /*uint*/width, /*uint*/height) | |
// ========================================================= | |
// Version 2.beta | 12-Nov-2014 | |
// -- Keep the message centered --see below the new method this.msg() | |
// -- Supports message patterns e.g: "Step %1/100" --see the sample code | |
// -- Other minor improvements | |
// ========================================================= | |
{ | |
(60<=(width||0))||(width=340); | |
(40<=(height||0))||(height=60); | |
var H = 22, | |
Y = (3*height-2*H)>>2, | |
W = new Window('palette', ' '+title, [0,0,width,height]), | |
P = W.add('progressbar', { x:20, y:height>>2, width:width-40, height:12 }, 0,100), | |
T = W.add('statictext' , { x:0, y:Y, width:width, height:H }), | |
__ = function(a,b){ return localize.apply(null,a.concat(b)) }; | |
this.pattern = ['%1']; | |
W.center(); | |
// --- | |
// API | |
// --- | |
this.msg = function(/*str*/s) | |
// --------------------------------- | |
{ | |
s && (T.location = [(width-T.graphics.measureString(s)[0])>>1, Y]); | |
T.text = s; | |
}; | |
this.show = this.reset = function(/*str*/s, /*uint*/v) | |
// --------------------------------- | |
{ | |
if( s && s != localize(s,1,2,3,4,5,6,7,8,9) ) | |
{ | |
this.pattern[0] = s; | |
s = __(this.pattern, [].slice.call(arguments,2)); | |
} | |
else | |
{ | |
this.pattern[0] = '%1'; | |
} | |
P.value = 0; | |
P.maxvalue = v||0; | |
P.visible = !!v; | |
this.msg(s); | |
W.show(); | |
}; | |
this.hit = function(x) | |
// --------------------------------- | |
{ | |
++P.value; | |
('undefined' != typeof x) && this.msg(/*P.value+'/'+P.maxvalue+': ' +*/__(this.pattern, [].slice.call(arguments,0))); | |
W.title = P.value+'/'+P.maxvalue+': '+title; | |
W.update(); | |
redraw(); | |
}; | |
this.hide = function() | |
// --------------------------------- | |
{ | |
W.hide(); | |
}; | |
this.close = function() | |
// --------------------------------- | |
{ | |
W.close(); | |
}; | |
}; | |
function setActiveArtboardByName(name) { | |
var artboard = a.getByName(name); | |
for (i = 0; i < a.length; i++) { | |
if (a[i] == artboard) { | |
a.setActiveArtboardIndex(i); | |
break; | |
} | |
} | |
} | |
function switchZero(z){ | |
for (var i = 0; i < zeroLayers.length; i++) { | |
l.getByName(zeroLayers[i]+'0').visible = (z=='0') ? true : false; | |
l.getByName(zeroLayers[i]+'00').visible = (z=='00') ? true : false; | |
}; | |
redraw(); | |
} | |
/* | |
function switchColor(c){ | |
$.writeln('switchColor: '+c); | |
for (var i = 0; i < coloredLayers.length; i++) { | |
var cl = l.getByName(coloredLayers[i]).groupItems; | |
cl.parent.visible = true; | |
// $.writeln('switchColor: '+cl.name +': l '+cl.layers.length +', g '+ cl.groupItems.length+ ';'); | |
// $.writeln('switchColor: '+cl.name +': l '+cl.layerItems.length +', g '+ cl.groupItems.length+ ';'); | |
// for (var j = 0; j < cl.length; j++) { | |
// cl[j].visible = (cl[j].name == c); | |
// $.writeln('switchColor: '+cl[j].name); | |
// }; | |
for (var j = 0; j < colors.length; j++) { | |
try{ | |
$.writeln('switchColor: '+colors[j]); | |
cl.getByName(colors[j]).hidden = (cl.getByName(colors[j]).name != c); | |
// cl.getByName(colors[j]).visible = (cl.getByName(colors[j]).name == c); | |
}catch(err){ | |
$.writeln('switchColor: '+coloredLayers[i]+' / '+colors[j] +' --- '+ err.message); | |
} | |
}; | |
}; | |
} | |
*/ | |
function rotatePhotoShopPNG(name,grayscale,saveAsBMP){ | |
var file = new File(filePath+exportPath+name+'.png'); | |
if(Junior.debug>0) $.writeln('rotatePhotoShopPNG: '+file+(grayscale?' GRAYSCALE ':' NOCONVERT ')+(saveAsBMP? 'BMP':'PNG')); | |
var psScript = 'app.displayDialogs = DialogModes.NO;'; | |
psScript += 'app.open('+file.toSource()+');'; | |
psScript += 'app.activeDocument.resizeImage( undefined,undefined,72,ResampleMethod.NONE);'; | |
if(grayscale){ | |
psScript += 'app.activeDocument.changeMode( ChangeMode.GRAYSCALE, Dither.NONE );'; | |
} | |
psScript += 'app.activeDocument.rotateCanvas( -90 );'; | |
if(saveAsBMP){ | |
psScript += 'var file = new File("'+filePath+exportPath+name+'.bmp'+'");'; | |
if(Junior.debug>1) psScript += '$.writeln("Photoshop new file: '+filePath+exportPath+name+'.bmp'+'");'; | |
psScript += 'var exportOptions = new BMPSaveOptions();'; | |
psScript += 'exportOptions.alphaChannels = false;'; | |
psScript += 'exportOptions.depth = BMPDepthType.'+(grayscale?'EIGHT':'BMP_R8G8B8')+';'; | |
psScript += 'app.activeDocument.saveAs(file, exportOptions, false, Extension.LOWERCASE);'; | |
if(Junior.debug>1) psScript += '$.writeln("Photoshop saveAs");'; | |
psScript += 'app.activeDocument.close( SaveOptions.DONTSAVECHANGES );'; | |
}else{ | |
psScript += 'app.activeDocument.close( SaveOptions.SAVECHANGES );'; | |
} | |
if(Junior.debug>1) psScript += '$.writeln("Photoshop close");'; | |
if(Junior.debug>1) $.writeln("Photoshop injection script ready:");; | |
psScript += 'app.displayDialogs = DialogModes.ALL;'; | |
btMessaging( 'photoshop', psScript ); | |
$.writeln('Photoshop injection complete'); | |
function btMessaging( targetApp, script ) { | |
var bt = new BridgeTalk(); | |
bt.target = targetApp; | |
bt.body = script; | |
bt.onResult = function( inBT ) { | |
p.hit('Photoshop -- success!'); | |
// if(Junior.debug>1) | |
$.writeln('Photoshop --- success!'); | |
}; | |
bt.onError = function( inBT ) { | |
p.hit( 'Photoshop -- so NOT Done…' ); | |
$.writeln('Photoshop -- so NOT Done…'); | |
sleep(100); | |
} | |
bt.send( 20 ); | |
}; | |
$.sleep(500); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment