scripting - Indesign脚本按顺序获取页面的所有文本框
问题描述
我正在尝试按顺序获取单个页面的所有文本框架,但是在使用
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
推荐阅读
- javascript - PHP 表单:服务器响应状态为 400(错误请求)
- javascript - 无法使用 jquery 将验证错误值打印到视图中
- r - 如何使用数据框创建具有绘图功能的循环函数
- excel - 防止 Excel 在时间戳中舍入微秒
- python - 你如何将一个模块添加到我的 PYTHONPATH 中?
- javascript - 发布ROS消息geometry/Point32需要什么格式
- java - 进行whatsapp视频通话
- firebase - Firebase云函数循环遍历数组并删除链接数据?
- css - CSS在固定标题下制作垂直滚动区域?
- javascript - 如何防止承诺在没有箭头功能的情况下丢失上下文