フレームグリッドの文字数と行数をスクリプト制御

InDesign ではすべての属性がスクリプト可能なのかと思いきや、フレームグリッドの基本情報である文字数/行数だけはなぜか簡単に読み書きする方法が用意されてない。日本語圏では頻繁に操作する箇所なので、自分でメソッドを作った。

  • 縦組み/横組み
  • テキストサイズ単位や組版単位などの違い
  • 段数、段間
  • 字間、行間
  • フレーム内マージン
  • フレームの線の太さ

などの設定をすべて考慮して、テキストフレームの geometricBounds から文字数と行数を逆算する仕組み。

TextFrame.prototype の拡張になっているので、外部ファイル扱い (.jsxinc) にしておいて #import で適宜読み込むのがおすすめ。

使い方

Getter と setter を兼ねた gridDimensions() というメソッドになっている。そのまま呼び出せば get、引数を渡して呼び出せば set として動作する。

フレームの種類が「フレームグリッド」に設定されているテキストフレームにのみ有効。フレームグリッドでない場合はエラーを返す。

Continue reading →

ScriptUI: Always honor Cancel/Esc in onClose validations

When you need to validate user input in an edittext field, it’s not enough to do so in its onChange event — you must also validate it in the dialog’s onClose. It’s the only way to stop the dialog from closing after a click on the OK button, so that the user has a chance to correct their input. But what if that close event occurred because of an explicit user action to simply dismiss the dialog, like clicking the Cancel button?

Continue reading →

Controlling measurementUnits

From pixels to points to ciceros, InDesign allows users to pick from 15 different measurement units to use in various places of their documents. Thanks to this versatility, it can sometimes be hard to predict how a script will act in a measurement unit environment even slightly different from yours.

Where are these measurement units?

There are three major places where measurement units could vary depending on the user environment:

Continue reading →

scriptPreferencesをバッチ変更→復元

スクリプト本体の実行前にユーザ設定値を変更しておき、本体実行後に元に戻す、という処理が頻出する。

特によくあるのが app.scriptPreferences の設定。 enableRedraw はほとんどの場合で disable したいだろうし、 measurementUnit は意図しない設定になっていると絶対値の組み込まれたアルゴリズムが不具合を起こす。

この辺の〈保持→変更→復元〉という処理を main() などに直接入れちゃうと煩雑なので、 scriptSettings.alter()scriptSettings.revert() で本体ルーチンを挟むだけでいいようにメソッド化してみた。

Continue reading →