【问题标题】:How to find ALL text frames in InDesign by JavaScript如何通过 JavaScript 在 InDesign 中查找所有文本框
【发布时间】:2017-11-30 12:20:06
【问题描述】:
我需要在 InDesign 文档的活动页面上找到所有文本框架并将它们放入一个数组中 - 以便获取一个或多个带有特定脚本标签的文本框架。我试过了
myPage = app.properties.activeWindow && app.activeWindow.activePage,
myTextFrames = myPage.textFrames.everyItem().getElements();
但这并没有带来那些被锚定的文本框架; - 在表格单元格中; ——在一个组内。我怎样才能得到真正的所有文本框架?
【问题讨论】:
标签:
javascript
scripting
frames
adobe-indesign
【解决方案1】:
不在一行中。
您可能需要从
myPage.allPageItems --> 返回一个数组并过滤它
arrayElement.constructor.name == "TextFrame"
或
arrayElement.label == "yourTargetLabel"
【解决方案2】:
//Array of every single pageItem in the document
var myItems = doc.allPageItems;
var n = myItems.length, tfs = [], nItem;
//Looping through page items to collect text frames
while ( n-- ) {
nItem = myItems[n];
(nItem instanceof TextFrame) && tfs.push ( nItem );
}
//result
alert( tfs.length + " textframes have been found" );
您也可以通过使用故事来反其道而行之:
//Storing all stories in the document.
var stories = doc.stories.everyItem().getElements(), n = stories.length, nStory, tfs = [];
//looping through stories to collect text frames
while ( n-- ) {
nStory = stories[n];
tfs.concat ( nStory.textContainers );
}
//result
alert( tfs.length + " textframes have been found" );
这可能会有所帮助。