簡體   English   中英

在InDesign中選擇后,如何獲得下一段?

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

我正在使用Adobe InDesign和ExtendScript來使用app.activeDocument.findGrep()查找關鍵字,我的這部分工作得很好。 我知道findGrep()返回一個Text對象數組。 假設我想使用第一個結果:

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

如何獲得下一段result

使用InDesign DOM

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

Indesign DOM具有不同的Text對象,可用於處理段落,單詞,字符或插入點(閃爍光標所在的字符之間的空間)。 一組Text對象稱為集合。 Indesign中的集合類似於數組,但一個顯着的區別是它們可以通過使用負索引( paragraphs[-1] )從后面解決。

result是指findGrep()的結果。 它可以是任何Text對象,具體取決於您的搜索條件。

paragraphs[-1]表示結果的最后一段(段落A)。 如果搜索結果只是一個單詞,那么這將引用單詞的封閉段落,而這個段落集合只有一個元素。

insertionPoints[-1]引用段落A的最后一個插入點。它出現段落標記之后和下一段落的第一個字符之前 (段落B)。 此insertedPoint屬於本段以下段落。

paragraphs[-1]返回insertionPoint的最后一段,即段落B(下一段)。

Althouh nextItem似乎完全合適且高效,它可能是性能泄漏的來源,特別是如果你在一個巨大的循環中多次調用它。 請記住,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(); 

沒有在這里聲稱絕對真理。 只是建議nextItem()可能出現的問題。

更簡單的代碼如下

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

謝謝

毫克。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM