テキストの位置を変えずに揃えを変更したい
テキストを位置を変えずに中央揃えするスクリプトをイラレとフォトショで作成してみて、AE版もチャレンジしてみました。
スケール値まで考慮できてなかったり、微妙に位置がずれたりと、完成度は低いですのであしからず。
目次
テキストを位置を変えずに中央揃えするスクリプト
座標を取得しておいて中央揃えにした後に元に戻す感じです。
app.beginUndoGroup("位置を変えずに揃える");
lay = app.project.activeItem.selectedLayers;
var myComp = app.project.activeItem;
for (i=0; i右揃えにする場合
揃えの種類を変更します。
var just = ParagraphJustification.LEFT_JUSTIFY; //左揃え
var just = ParagraphJustification.RIGHT_JUSTIFY;//右揃え
var just = ParagraphJustification.CENTER_JUSTIFY; //中央揃え位置を変えずに右揃えにする場合:
//中央揃え▶右揃え
if (beforeJust == justCenter) {
var rectL = myTextLayer.sourceRectAtTime(0, false).left;
myTextLayer.property("ADBE Transform Group").property("ADBE Position").setValue([posX - rectL / 2, posY]);
}
//左揃え▶右揃え
if (beforeJust == justLeft) {
var rectL = myTextLayer.sourceRectAtTime(0, false).left;
myTextLayer.property("ADBE Transform Group").property("ADBE Position").setValue([posX - rectL, posY]);
}左揃えにする場合
//中央揃え▶左揃え
if (beforeJust == justCenter) {
var rectL = myTextLayer.sourceRectAtTime(0, false).left;
myTextLayer.property("ADBE Transform Group").property("ADBE Position").setValue([posX + rectL, posY]);
}
//右揃え▶左揃え
if (beforeJust == justRight) {
var rectL = myTextLayer.sourceRectAtTime(0, false).left;
myTextLayer.property("ADBE Transform Group").property("ADBE Position").setValue([posX + rectL, posY]);
}こちらはmyTextDoc.justification = just;の前に挿入します。
位置合わせの座標を取得したり、ズレた分を計算したりする必要があるのですが、自分の数学的な選択肢が四則計算しかないのでもっと良い方法があったら改良します。
