简体   繁体   English

在InDesign中选择后,如何获得下一段?

[英]How can I get the next paragraph after my selection in InDesign?

I'm using Adobe InDesign and ExtendScript to find a keyword using app.activeDocument.findGrep() , and I've got this part working well. 我正在使用Adobe InDesign和ExtendScript来使用app.activeDocument.findGrep()查找关键字,我的这部分工作得很好。 I know findGrep() returns an array of Text objects. 我知道findGrep()返回一个Text对象数组。 Let's say I want to work with the first result: 假设我想使用第一个结果:

var result = app.activeDocument.findGrep()[0];

How can I get the next paragraph following result ? 如何获得下一段result

Use the InDesign DOM 使用InDesign DOM

var nextParagraph = result.paragraphs[-1].insertionPoints[-1].paragraphs[-1];

The Indesign DOM has different Text objects that you can use to address paragraphs, words, characters, or insertion points (the space between characters where your blinking cursor sits). Indesign DOM具有不同的Text对象,可用于处理段落,单词,字符或插入点(闪烁光标所在的字符之间的空间)。 A group of Text objects is called a collection. 一组Text对象称为集合。 Collections in Indesign are similar to arrays, but one significant difference is that they can be addressed from the back by using a negative index ( paragraphs[-1] ). Indesign中的集合类似于数组,但一个显着的区别是它们可以通过使用负索引( paragraphs[-1] )从后面解决。

result refers to the findGrep() result. result是指findGrep()的结果。 It can be any Text object, depending on your search terms. 它可以是任何Text对象,具体取决于您的搜索条件。

paragraphs[-1] means the last paragraph of your result (Paragraph A). paragraphs[-1]表示结果的最后一段(段落A)。 If the search result is just one word, then this refers the word's enclosing paragraph, and this collection of paragraphs has just one element. 如果搜索结果只是一个单词,那么这将引用单词的封闭段落,而这个段落集合只有一个元素。

insertionPoints[-1] refers to the last insertionPoint of Paragraph A. This comes after the paragraph mark and before the first character of the next paragraph (Paragraph B). insertionPoints[-1]引用段落A的最后一个插入点。它出现段落标记之后和下一段落的第一个字符之前 (段落B)。 This insertionPoint belongs to both this paragraph and the following paragraph. 此insertedPoint属于本段以下段落。

paragraphs[-1] returns the last paragraph of the insertionPoint, which is Paragraph B (the next paragraph). paragraphs[-1]返回insertionPoint的最后一段,即段落B(下一段)。

Althouh nextItem seems totally appropriate and efficient, it may be a source of performance leaks especially if you call it several times in a huge loop. Althouh nextItem似乎完全合适且高效,它可能是性能泄漏的来源,特别是如果你在一个巨大的循环中多次调用它。 Keep in mind that nextItem() is a function creating an internal scope and stuff… An alternative is to navigate within the story and reach the next paragraph thanks to the insertionPoints indeces: 请记住,nextItem()是一个创建内部范围和内容的函数......另一种方法是在故事中导航并通过insertPoints indeces到达下一段:

 var main = function() { var doc, found, st, pCurr, pNext, ipNext, ps; if (!app.documents.length) return; doc = app.activeDocument; app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.findWhat = "\\\\A."; found = doc.findGrep(); if ( !found.length) return; found = found[0]; st = found.parentStory; pCurr = found.paragraphs[0]; ipNext = st.insertionPoints [ pCurr.insertionPoints[-1].index ]; var pNext = ipNext.paragraphs[0]; alert( pNext.contents ); }; main(); 

Not claiming the absolute truth here. 没有在这里声称绝对真理。 Just advising about possible issues with nextItem(). 只是建议nextItem()可能出现的问题。

more simply code below 更简单的代码如下

result.paragraphs.nextItem(result.paragraphs[0]);

thank you 谢谢

mg. 毫克。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InDesign:如何获得带有characterStyles的段落内容? - InDesign: How can I get paragraph contents with its characterStyles? 如何在InDesign中获得所选文本之后的第一个字符? - How can I get the first character after the selected text in InDesign? Indesign脚本-如何在线程文本框中获取第一段 - Indesign script - How to get first paragraph in threaded text frame Indesign:在表格单元格中,如何获取和移动任何段落内容 - Indesign : in a table cell, how to get and move any paragraph content 如何使用JavaScript在Indesign CS6中找到文本框架? (我可以通过包含特定段落样式或什么样式的文本框架进行查询) - How to find a text frame in Indesign CS6 with javascript? (I can query by text-frames containing a particular paragraph style or what?) InDesign CS5 脚本:如何在 `n` 秒后打开和关闭弹出窗口? - InDesign CS5 Script: How can I open and close a popup window after `n` seconds? 单击按钮后如何获取数组的下一个项目? - How can I get the next items of an array after clicking on a button? 我如何修复我的代码以将每个段落放在一个新行中,因为我试图在给定段落之前添加段落 - How can i fix my code to put each paragraph in a new line, as I am trying to add paragraph before the given paragraph 段落淡入后如何立即淡出? - How can I fade a paragraph out right after it was faded in? 如何在段落中添加行号? - How can I add line numbering to my paragraph?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM