Adobe inDesign scriptを書くときの初期設定用スクリプト

毎回変数に諸々の設定値などを詰め込むのがめんどうなので、オレオレ設定の初期設定よう関数を作った。グローバル変数まみれなのできちんとやっている人にとっては悶絶だとは思うが、あしからず。

function initialSetting() {
//indesignファイルを配置する時の初期設定
indsignPageAttributes = app.importedPageAttributes;
indsignPageAttributes.pageNumber = 1;
//newDocuFlagによって新規にドキュメントを作るか既存のものを使うか
if (is_flag(newDocuFlag)) {
docuObj = app.documents.add();
with (docuObj.documentPreferences) {
pageWidth = "297mm";
pageHeight = "210mm";
facingPages = false;
pagesPerDocument = 1;
}
} else {
docuObj = app.activeDocument;
}
//単位をミリに設定設定
docuObj.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
docuObj.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
//ドキュメントの高さやマージンの設定
docuPreference = docuObj.documentPreferences;
docuPageHeight = docuPreference.pageHeight;
docuPageWidth = docuPreference.pageWidth;
//マージン関係
with (docuObj.pages[0].marginPreferences) {
top = 7;
left = 7;
right = 7;
bottom = 7;
}
//マージン取得
docuMarginTop = docuObj.pages[0].marginPreferences.top;
docuMarginLeft = docuObj.pages[0].marginPreferences.left;
docuMarginRight = docuObj.pages[0].marginPreferences.right;
docuMarginBottom = docuObj.pages[0].marginPreferences.bottom;
//マージンを差し引いたドキュメント幅
docuPageMaxWidh = docuPageWidth - docuMarginLeft - docuMarginRight;
docuPageMaxHeight = docuPageHeight - docuMarginTop - docuMarginBottom;
}
function is_flag(flag) {
if (flag !== true && fkag !== false) return flag;
return flag;
}
newDocuFlag = true;
initialSetting();

A4でドキュメントを作ったりページオブジェクトを設定したり、デフォルト単位をミリにしたりマージン用変数を作ったりといった感じ。

newDocuFlagをtrueにすれば新しくドキュメントを作ってスクリプトを始められるぜ、いえい。