Skip to content

Instantly share code, notes, and snippets.

@AJABON
Last active May 28, 2020 23:59
Show Gist options
  • Save AJABON/b1ee2a52b118ede7af2538ca6572abe4 to your computer and use it in GitHub Desktop.
Save AJABON/b1ee2a52b118ede7af2538ca6572abe4 to your computer and use it in GitHub Desktop.
// Illustratorで位置キープで文字揃え方向を変えるやつ
//2016.06.30 使用頻度の高い「右 / 下揃え」をOKボタン属性に変更
//2016.06.27 ドロップダウンリスト触りにくいのでボタン群に変更
//2016.06.20 CS4以降の左揃えの不具合を修正
// 2016.05.18 by(z-)
function main () {
if (! app.documents.length) return;
var sel = app.activeDocument.selection;
var obj, top, left;
var pepsi = { };
pepsi ["左 / 上揃え"] = Justification.LEFT; //揃えオブジェクト
pepsi ["中央揃え"] = Justification.CENTER;
pepsi ["右 / 下揃え"] = Justification.RIGHT;
while (sel.length) { // いちおうよくばりループ
obj = sel.shift ();
if (obj.reflect.name == "GroupItem"){ //単一オブジェクトによるグループは救済
if (obj.pageItems.length == 1){
obj = obj.pageItems[0];
}
}
if (!obj.reflect.name.match(/TextFrame|Array/)) continue; //ここ未検証てきとう(若干改善)
top = obj.top;
left = obj.left;
if (val == win.BL.text) { //左揃えならリサイズしておく
obj.resize(200, 200);
}
changeJustification (obj, pepsi[val]);
if (val == win.BL.text) { //リサイズを戻しておく
obj.resize(50, 50);
}
obj.top = top;
obj.left = left;
}
}
function changeJustification (obj, val) { // 揃え方向を変更
obj.story.textRange.justification=val;
}
function bFunc(obj) {
val = obj.text;
win.close();
}
var dlg="dialog{orientation:'row', text:'justificationSwitcher', \
BL:Button{text:'左 / 上揃え'}, \
BC:Button{text:'中央揃え'}, \
BR:Button{text:'右 / 下揃え', properties:{name:'ok'}}\
}";
var val;
var win = new Window (dlg);
win.spacing -= 8;
win.BL.onClick = function(){ bFunc(this);}
win.BC.onClick = function(){ bFunc(this);}
win.BR.onClick = function(){ bFunc(this);}
var res = win.show ();
if (res != 2) main ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment