-
-
Save cg-method/e43678eb6720944d5871f63cf106fd5e to your computer and use it in GitHub Desktop.
レイヤー操作:選択範囲を四角で選択する
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
function clippingArea() { | |
// レイヤー内の不透明なエリアのクリッピング | |
//--------------------------2003.10.24 新瀬 進(http://www.os.rim.or.jp/~furu/) | |
// アクティブレイヤー以外を不可視に=========================================== | |
function visibleActiveOnly(docRef){ | |
var loop; | |
var visible = new Array(); //元の表示状態保存配列 | |
for(loop=0; loop<docRef.layers.length; loop++){ | |
visible[loop] = docRef.layers[loop].visible; | |
if(docRef.layers[loop].visible){ docRef.layers[loop].visible = false; } | |
} | |
docRef.activeLayer.visible = true; //アクティブレイヤーを表示 | |
return visible; | |
} | |
// 表示状態を元に戻す========================================================= | |
function visibleOriginal(docRef, visible){ | |
var loop; | |
for(loop=0; loop<docRef.layers.length; loop++){ | |
docRef.layers[loop].visible = visible[loop]; | |
} | |
return true; | |
} | |
// クリッピングエリア検索クラス=============================================== | |
function ClippingArea(docRef){ | |
var x_size = docRef.width; //画像の横幅 | |
var y_size = docRef.height; //画像の縦幅 | |
var before = docRef.activeHistoryState; //ヒストリーを保存 | |
docRef.trim(TrimType.TRANSPARENT,true,true,false,false); // 左上をトリミング | |
var x_offset = x_size - docRef.width; | |
var y_offset = y_size - docRef.height; | |
docRef.trim(TrimType.TRANSPARENT,true,true,true,true); // トリミング | |
var x_trim_size = docRef.width; | |
var y_trim_size = docRef.height; | |
docRef.activeHistoryState = before; // 画像サイズを元に戻す | |
// ClippingAreaクラスのプロパティとして戻り値を設定--------------------------- | |
this.left = x_offset; | |
this.right = x_offset + x_trim_size; | |
this.top = y_offset; | |
this.bottom = y_offset + y_trim_size; | |
} | |
//============================================================================ | |
//使用例・クリッピング座標を選択 | |
var strtRulerUnits = preferences.rulerUnits; | |
if(strtRulerUnits != Units.PIXELS){ preferences.rulerUnits = Units.PIXELS; } | |
var srcDoc = activeDocument; | |
var v_array = visibleActiveOnly(srcDoc); | |
var xy = new ClippingArea(srcDoc); | |
visibleOriginal(srcDoc, v_array); | |
srcDoc.selection.select(Array (Array(xy.left, xy.top), Array(xy.right, xy.top), Array(xy.right, xy.bottom), Array(xy.left, xy.bottom)), SelectionType.REPLACE, 0, false); | |
if(strtRulerUnits != Units.PIXELS){ preferences.rulerUnits = strtRulerUnits; } | |
srcDoc = null; | |
xy = null; | |
v_array = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment