Last active
May 10, 2020 12:36
-
-
Save UskeS/7de00a21301b907a21aba5b8ca784b87 to your computer and use it in GitHub Desktop.
[InDesign][ExtendScript] 選択している段落スタイルを検索し、ストーリー上で同じ段落スタイルが当たっている次の/前の段落にジャンプする
This file contains 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
/** | |
* fileoverview 選択しているテキストに適用されている段落スタイルを検索し、同じ段落スタイルが適用された次のテキストにジャンプする | |
* @author SAEGUSA Yusuke | |
* @version 0.0.1 | |
*/ | |
if (app.documents.length === 0 || app.selection.length === 0) { | |
myError("001"); | |
} | |
var doc = app.activeDocument; | |
var sel = doc.selection[0]; | |
if (!sel.hasOwnProperty("appliedParagraphStyle")) { | |
myError("001"); | |
} | |
var curStory = sel.parentStory; | |
var curIndex = sel.index; | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
app.findGrepPreferences.appliedParagraphStyle = sel.appliedParagraphStyle; | |
var found = curStory.findGrep(); | |
var result = false; | |
for (var i=0, len=found.length; i<len; i++) { | |
if (found[i].index > curIndex) { | |
found[i].select(); | |
found[i].showText(); | |
result = true; | |
break; | |
} | |
} | |
if (!result) { | |
myError("002"); | |
} | |
function myError(erNum) { | |
var errorMessage = { | |
"001": "テキストを選択してから実行してください", | |
"002": "同じスタイルがキャレット以降で見つかりません", | |
}; | |
alert(errorMessage[erNum]); | |
exit(); | |
} |
This file contains 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
/** | |
* fileoverview 選択しているテキストに適用されている段落スタイルを検索し、同じ段落スタイルが適用された前のテキストにジャンプする | |
* @author SAEGUSA Yusuke | |
* @version 0.0.1 | |
*/ | |
if (app.documents.length === 0 || app.selection.length === 0) { | |
myError("001"); | |
} | |
var doc = app.activeDocument; | |
var sel = doc.selection[0]; | |
if (!sel.hasOwnProperty("appliedParagraphStyle")) { | |
myError("001"); | |
} | |
var curStory = sel.parentStory; | |
var curIndex = sel.paragraphs[0].index; | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
app.findGrepPreferences.appliedParagraphStyle = sel.appliedParagraphStyle; | |
var found = curStory.findGrep(); | |
var result = false; | |
for (var i=found.length-1; i>=0; i--) { | |
if (found[i].index < curIndex) { | |
found[i].select(); | |
found[i].showText(); | |
result = true; | |
break; | |
} | |
} | |
if (!result) { | |
myError("002"); | |
} | |
function myError(erNum) { | |
var errorMessage = { | |
"001": "テキストを選択してから実行してください", | |
"002": "同じスタイルがキャレット以前に見つかりません", | |
}; | |
alert(errorMessage[erNum]); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment