JavaScript 如何在 InDesign 中查找所有文本框

How to find ALL text frames in InDesign by JavaScript

我需要在 InDesign 文档中找到活动页面上的所有文本框架并将它们放入一个数组中 - 以便抓取一个或多个带有特定脚本标签的文本框架。我试过了

myPage = app.properties.activeWindow && app.activeWindow.activePage,
myTextFrames = myPage.textFrames.everyItem().getElements();

但这不会带来那些锚定的文本框; - 在 table 单元格中; - 在一个组内。我怎样才能真正获得所有文本框?

不在一行中。

您可能需要从 myPage.allPageItems --> returns 一个数组并通过

过滤它
  1. arrayElement.constructor.name == "TextFrame"

  1. arrayElement.label == "yourTargetLabel"

//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" );

这可能会有所帮助。