Indesign脚本以按顺序获取页面的所有文本框
Indesign scripting to get all textframes of a page in order
我试图按顺序获取单个页面的所有文本框架,但在使用
时我总是以随机顺序获取它们
myDoc.pages[1] //assuming the 1st index page
>> [object Page]
myDoc.pages[eachPage].textFrames //get all the text frames on that page.
>> [object TextFrames] //able to get the textframes but they are not in the order if they are linked textframes
如果它们是链接的文本框,有没有办法让它们按顺序排列? (不确定如果取消链接它们将如何出现)
如果不是,至少如何知道页面上的第一个文本框架,以便我可以使用 . nextTextFrame
获得其他框架。
基本上,您必须从任何文本框架开始,然后从中找到所有链接的文本框架,然后在第三步中仅收集您页面上的那些文本框架。以下是您的操作方法:
// get your document and your page somehow
var doc = app.activeDocument;
var myPage = doc.pages[1];
// get any text frame on your page and from its parent story get the
// text containers which is an array of all text frames that contain
// the linked text story
var someTextFrame = myPage.textFrames[0];
var textContainers = someTextFrame.parentStory.textContainers;
// loop over all text containers in order and collect those that are
// on your page
var textFramesInOrder = [];
for (var i = 0; i < textContainers.length; i++) {
if(textContainers[i].parentPage === myPage) {
textFramesInOrder.push(textContainers[i]);
}
}
// now textFramesInOrder holds all the text frames of the page in correct order
我试图按顺序获取单个页面的所有文本框架,但在使用
时我总是以随机顺序获取它们myDoc.pages[1] //assuming the 1st index page
>> [object Page]
myDoc.pages[eachPage].textFrames //get all the text frames on that page.
>> [object TextFrames] //able to get the textframes but they are not in the order if they are linked textframes
如果它们是链接的文本框,有没有办法让它们按顺序排列? (不确定如果取消链接它们将如何出现)
如果不是,至少如何知道页面上的第一个文本框架,以便我可以使用 . nextTextFrame
获得其他框架。
基本上,您必须从任何文本框架开始,然后从中找到所有链接的文本框架,然后在第三步中仅收集您页面上的那些文本框架。以下是您的操作方法:
// get your document and your page somehow
var doc = app.activeDocument;
var myPage = doc.pages[1];
// get any text frame on your page and from its parent story get the
// text containers which is an array of all text frames that contain
// the linked text story
var someTextFrame = myPage.textFrames[0];
var textContainers = someTextFrame.parentStory.textContainers;
// loop over all text containers in order and collect those that are
// on your page
var textFramesInOrder = [];
for (var i = 0; i < textContainers.length; i++) {
if(textContainers[i].parentPage === myPage) {
textFramesInOrder.push(textContainers[i]);
}
}
// now textFramesInOrder holds all the text frames of the page in correct order