Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save monokano/db0a4e236d47616f38e43c811b2ede50 to your computer and use it in GitHub Desktop.

Select an option

Save monokano/db0a4e236d47616f38e43c811b2ede50 to your computer and use it in GitHub Desktop.
索引を条件テキスト「索引」でマーカーするInDesignスクリプト
var doc = app.activeDocument;
var index = doc.indexes[0];
var topics = index.topics;
var conditionName = "索引";
var indexCondition = null;
// 条件テキスト「索引」が存在するか確認(forループで安全に)
for (var i = 0; i < doc.conditions.length; i++) {
if (doc.conditions[i].name === conditionName) {
indexCondition = doc.conditions[i];
break;
}
}
// 存在しなければ新規作成
if (indexCondition === null) {
indexCondition = doc.conditions.add({
name: conditionName,
visible: true,
indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT,
indicatorColor: UIColors.YELLOW
});
}
// 各トピックに対して処理を実行
for (var i = 0; i < topics.length; i++) {
var topic = topics[i];
var nameLength = topic.name.length;
var pageRefs = topic.pageReferences;
for (var j = 0; j < pageRefs.length; j++) {
var ref = pageRefs[j];
var sourceText = ref.sourceText;
// 挿入点の位置とストーリーを取得
var startIndex = sourceText.insertionPoints[0].index;
var story = sourceText.parentStory;
var endIndex = startIndex + nameLength;
// 範囲を取得
var textRange = story.characters.itemByRange(startIndex, endIndex);
// 条件テキスト「索引」を適用
textRange.applyConditions([indexCondition]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment