Last active
June 1, 2025 02:42
-
-
Save monokano/db0a4e236d47616f38e43c811b2ede50 to your computer and use it in GitHub Desktop.
索引を条件テキスト「索引」でマーカーするInDesignスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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