如果你不想使用grep,你可以通过你有兴趣与应用了一定的风格收集段故事的每个段落重复。
在下面我示例代码收集在para_with_style
变量的段落:
var doc = app.activeDocument;
var story = doc.stories[0];
// Get every paragraph in `story` (using `everyItem().getElements()` is more efficient)
var paras = story.paragraphs.everyItem().getElements();
// Collect every paragraph with a certain paragraph style
var applied_style = doc.paragraphStyles.itemByName('style-name');
var paras_with_style = [];
for (var i=0,l=paras.length; i<l; i++) {
var para = paras[i];
if (para.appliedParagraphStyle == applied_style) {
paras_with_style.push(para);
}
}
// Do something with each `para` in `paras_with_style`