Skip to content

Instantly share code, notes, and snippets.

@K-atc
Last active July 28, 2018 16:24
Show Gist options
  • Save K-atc/92691fe7ca30efd506ca to your computer and use it in GitHub Desktop.
Save K-atc/92691fe7ca30efd506ca to your computer and use it in GitHub Desktop.
作業ファイルと同じフォルダにoutputフォルダを作り、その中にグループ毎にJPEG書き出しを行うスクリプト
// 参考: http://yukimi.moemoe.gr.jp/MT/archives/2011/10/
#target photoshop
//配列内にobjがあるかをチェック
function check_array(target_array,obj){
for (var i in target_array){
if (target_array[i] == obj){
return true;
break;
}
}
return false;
}
//名前の重複を調べて再割当て
function chack_name(array1,name1){
if (! check_array(array1,name1)){
return name1;
}else{
//序数
var tag = 1;
//同一名が100以上になることは考えない
while (tag < 100){
var name2 = name1 + "_" + tag;
if (! check_array(array1,name2)){
return name2;
}
tag += 1;
}
}
}
//JPEGで保存
function save_JPG(file_path){
jpgFile = new File(file_path);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 11;
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
//main
// in case we double clicked the file
//app.bringToFront();
app.displayDialogs = DialogModes.NO;
//ドキュメントが開かれているかどうか判別
if (app.documents.length ==0)
{
//ドキュメントが開かれていない場合処理なし
}
else
{
//Folder.selectDialog ([prompt]) :出力先を指定
//var outputDir = Folder.selectDialog (["Plese select output directory"]);
var outputDir = activeDocument.path + "/output" ;
var folder = Folder(outputDir);
//Check if it exist, if not create it.
if(!folder.exists) folder.create();
//選択されてない場合はnullが返る
//alert(outputDir );
if (outputDir != null){
//作業するドキュメントを取得
var active_doc = activeDocument;
try {
//ルート階層にあるレイヤーセットを取得
var docLayerSets= activeDocument.layerSets;
//ルート階層にある全てのレイヤーを取得
var docArtLyaers= activeDocument.layers;
var docArtLyaerCount = docArtLyaers.length
//レイヤの表示状態を退避する配列を作成
layer_v_array = new Array(docArtLyaerCount);
//全てのレイヤーの表示状態を取得して非表意に
for (i = 0; i < docArtLyaerCount; i++){
//表示状態の取得
layer_v_array[i] = docArtLyaers[i] .visible;
//非表示に
docArtLyaers[i] .visible = false;
}
//ファイル名の重複チェックのための配列
name_array = new Array(docLayerSets.length);
//グループの書き出し
for (i = 0; i < docLayerSets.length; i++){
//レイヤを表示
docLayerSets[i].visible = true;
//レイヤ名の取得
layer_name = docLayerSets[i].name;
//ファイル名の重複がないか処理
layer_name = chack_name(name_array,layer_name);
//名前のリストに追加
name_array[i] = layer_name;
//ファイルパスの生成
var file_path = outputDir + "/" + layer_name + ".jpg";
//alert(file_path);
//ファイルの書き出し
save_JPG(file_path);
//対象レイヤーを非表示に
docLayerSets[i].visible = false;
}
//レイヤの表示を元の様態に戻す
for (i = 0; i < docArtLyaerCount; i++){
//表示状態の取得
docArtLyaers[i] .visible = layer_v_array[i];
}
} catch (e) {
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert(e);
}
//return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
}
}
@K-atc
Copy link
Author

K-atc commented Feb 7, 2015

78行目付近

 //非表示に
docArtLyaers[i] .visible = false; 

をコメントアウトするとグループの外にあるルート階層のレイヤーの表示状態が維持されます。

@K-atc
Copy link
Author

K-atc commented Feb 7, 2015

layerSetはグループのこと?

@hiroCokuda
Copy link

K-actさん

奥田と申します。

本コードですが、商用での利用、改変などは許容されていますでしょうか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment