Skip to content

Instantly share code, notes, and snippets.

@whaison
Created August 3, 2015 06:43
Show Gist options
  • Save whaison/a6b16a258e1ebf2903b0 to your computer and use it in GitHub Desktop.
Save whaison/a6b16a258e1ebf2903b0 to your computer and use it in GitHub Desktop.
#target photoshop
//
// pngToTga.jsx
//
//
// Generated Thu Jun 18 2015 18:07:14 GMT+0900
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== pngToTga ==============
//
var myFilePathStr="";
var myFilePathArr=new Array();
var myFilePathDir="";
var myFileNameStr="";
var myFileNameArr=new Array();
var myFileNameDotArr=new Array();
var myCharacterBaseName="";
var TgaFilePath="";
function pngToTga() {
// //Tga保存先設定•
function step0(){
//JSの場所
/*
const SELF = (function(){
try {app.documents.test()}
catch(e) {return File(e.fileName)}
})();
//$.writeln(SELF instanceof File);
// $.writeln(SELF);
// $.writeln(SELF.path)
myFilePathStr=SELF.path;
$.writeln("myFilePathStr"+myFilePathStr+"")
$.writeln("$.fileName"+$.fileName)
*/
//Tga保存先設定
myFilePathDir = activeDocument.path;
$.writeln("myFilePathDir= "+myFilePathDir+"")
myFileNameStr=activeDocument.name;
$.writeln("myFileNameStr= "+myFileNameStr+"")
myFileNameArr=myFileNameStr.split ("_");
$.writeln("myFileNameArr= "+myFileNameArr+"")
myFileNameDotArr=myFileNameStr.split (".");
$.writeln("myFileNameArr.length= "+myFileNameArr.length+"")
if(myFileNameArr.length>1){
//ネームルール用
myCharacterBaseName=myFileNameArr[0]+"_"+myFileNameArr[1]+"_"+myFileNameArr[2]+"_";
$.writeln("myCharacterBaseName= "+myCharacterBaseName+"")
TgaFilePath=myFilePathDir+"/"+myCharacterBaseName+"tga.tga";
}else{
//普通ファイル用
myCharacterBaseName=myFileNameDotArr[0]+"_";
$.writeln("myCharacterBaseName= "+myCharacterBaseName+"")
TgaFilePath=myFilePathDir+"/"+myCharacterBaseName+"tga.tga";
}
$.writeln("TgaFilePath= "+TgaFilePath+"")
}
//TGAに保存する。
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putInteger(cTID('BtDp'), 32);
desc2.putInteger(cTID('Cmpr'), 0);
desc1.putObject(cTID('As '), cTID('TrgF'), desc2);
//desc1.putPath(cTID('In '), new File("/Share/jsx_mel/Sotai/sd_0016_victoria/sd_0016_victoria_tga.tga"));
desc1.putPath(cTID('In '), new File(TgaFilePath));
desc1.putInteger(cTID('DocI'), 2139);
desc1.putBoolean(cTID('Cpy '), true);
desc1.putBoolean(cTID('LwCs'), true);
executeAction(sTID('save'), desc1, dialogMode);
};
// 選択範囲 透明部分チャンネル
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Trsp'));
desc1.putReference(cTID('T '), ref2);
executeAction(sTID('set'), desc1, dialogMode);
};
// 複製選択範囲 chara
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putString(cTID('Nm '), "chara");
executeAction(sTID('duplicate'), desc1, dialogMode);
};
// 作成レイヤー
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass(cTID('Lyr '));
desc1.putReference(cTID('null'), ref1);
executeAction(sTID('make'), desc1, dialogMode);
};
// 選択範囲を反転
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(sTID('inverse'), undefined, dialogMode);
};
// 描画色を黒に設定
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Clr '), cTID('FrgC'));
desc1.putReference(cTID('null'), ref1);
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('H '), cTID('#Ang'), 359.994506835938);
desc2.putDouble(cTID('Strt'), 0);
desc2.putDouble(cTID('Brgh'), 0);
desc1.putObject(cTID('T '), cTID('HSBC'), desc2);
desc1.putString(cTID('Srce'), "photoshopPicker");
executeAction(sTID('set'), desc1, dialogMode);
};
// 塗り潰し
function step7(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 1);
desc2.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1);
desc1.putObject(cTID('From'), cTID('Pnt '), desc2);
desc1.putInteger(cTID('Tlrn'), 32);
desc1.putBoolean(cTID('AntA'), true);
desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('FrgC'));
executeAction(sTID('fill'), desc1, dialogMode);
};
// レイヤーを作成
function step8(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass(cTID('Lyr '));
desc1.putReference(cTID('null'), ref1);
executeAction(sTID('make'), desc1, dialogMode);
};
// 描画色の設定 白
function step9(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Clr '), cTID('FrgC'));
desc1.putReference(cTID('null'), ref1);
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('H '), cTID('#Ang'), 359.994506835938);
desc2.putDouble(cTID('Strt'), 0);
desc2.putDouble(cTID('Brgh'), 100);
desc1.putObject(cTID('T '), cTID('HSBC'), desc2);
desc1.putString(cTID('Srce'), "photoshopPicker");
executeAction(sTID('set'), desc1, dialogMode);
};
// 選択範囲すべて
function step10(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putEnumerated(cTID('T '), cTID('Ordn'), cTID('Al '));
executeAction(sTID('set'), desc1, dialogMode);
};
//描画色 白で塗り潰し
function step11(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 1);
desc2.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1);
desc1.putObject(cTID('From'), cTID('Pnt '), desc2);
desc1.putInteger(cTID('Tlrn'), 32);
desc1.putBoolean(cTID('AntA'), true);
desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('FrgC'));
executeAction(sTID('fill'), desc1, dialogMode);
};
// 白で塗り潰したレイヤーを 黒の裏に移動
function step12(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putIndex(cTID('Lyr '), 1);
desc1.putReference(cTID('T '), ref2);
desc1.putBoolean(cTID('Adjs'), false);
desc1.putInteger(cTID('Vrsn'), 5);
executeAction(sTID('move'), desc1, dialogMode);
};
// レイヤー1の表示を使用しない
function step13(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "レイヤー 1");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
executeAction(sTID('select'), desc1, dialogMode);
};
// レイヤーを結合‡
function step14(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
executeAction(sTID('mergeLayersNew'), desc1, dialogMode);
};
// 選択範囲すべて
function step15(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putEnumerated(cTID('T '), cTID('Ordn'), cTID('Al '));
executeAction(sTID('set'), desc1, dialogMode);
};
//コピー
function step16(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(sTID('copyEvent'), undefined, dialogMode);
};
// TGA開く
function step17(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
//desc1.putPath(cTID('null'), new File("/Share/jsx_mel/Sotai/sd_0016_victoria/sd_0016_victoria_tga.tga"));
desc1.putPath(cTID('null'), new File(TgaFilePath));
executeAction(sTID('open'), desc1, dialogMode);
};
// アルファチャンネル1選択
function step18(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Chnl'), "アルファチャンネル 1");
desc1.putReference(cTID('null'), ref1);
executeAction(sTID('select'), desc1, dialogMode);
};
// 選択範囲すべて
function step19(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putEnumerated(cTID('T '), cTID('Ordn'), cTID('Al '));
executeAction(sTID('set'), desc1, dialogMode);
};
// ペースト
function step20(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('AntA'), cTID('Annt'), cTID('Anno'));
executeAction(sTID('paste'), desc1, dialogMode);
};
// 表示:RGBチャンネル
function step21(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Rd '));
list1.putReference(ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Grn '));
list1.putReference(ref2);
var ref3 = new ActionReference();
ref3.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Bl '));
list1.putReference(ref3);
desc1.putList(cTID('null'), list1);
executeAction(sTID('show'), desc1, dialogMode);
};
// 保存
function step22(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(sTID('save'), undefined, dialogMode);
};
//閉じる。
function step23(enabled, withDialog){
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
step0(); ////Tga保存先設定
step1(); // //TGAに保存する。
step2(); //// 選択範囲 透明部分チャンネル
step3(); // // 複製選択範囲 chara
step4(); //// 作成レイヤー
step5(); //// 選択範囲を反転
step6(); //// 描画色を黒に設定
step7(); //// 塗り潰し
step8(); // // レイヤーを作成
step9(); // // 描画色の設定 白
step10(); //// 選択範囲すべて
step11(); ////描画色 白で塗り潰し
step12(); //// 白で塗り潰したレイヤーを 黒の裏に移動
step13(); // // レイヤー1の表示を使用しない
step14(); //// レイヤーを結合‡Œ‹‡
step15(); //// 選択範囲すべて
step16(); ////コピー
step17(); //// TGA開く
step18(); // // アルファチャンネル1選択
step19(); //// 選択範囲すべて
step20(); //// ペースト
step21(); // // 表示:RGBチャンネル
step22(); // 保存
step23(); //閉じる。
};
//=========================================
// pngToTga.main
//=========================================
//
pngToTga.main = function () {
pngToTga();
};
pngToTga.main();
// EOF
"pngToTga.jsx"
// EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment