简体   繁体   English

Select InDesign (Javascript) 的所有奇数页中的所有文本框架和 ALIGN RIGHT

[英]Select all text frames and ALIGN RIGHT in all ODD numbered pages of InDesign (Javascript)

I want to select all text frames and then ALIGN its content to the right of the page of all the ODD numbered pages of my document in InDesign using only Javascript.我想 select 所有文本框架,然后仅使用 Javascript 将其内容对齐到 InDesign 中我的文档的所有奇数页的页面右侧。

here's my progress so far and I know I can determine the odd numbers but still can't make selecting a page work thus no progress to select its text frames too.这是我到目前为止的进展,我知道我可以确定奇数,但仍然无法选择页面,因此 select 的文本框架也没有进展。

main();
function main() {
  var myDocument = app.documents.item(0);
  var myPage = myDocument.pages.item(0);
  var i = 0;

  for (i = 1; i < myDocument.pages.count(); i = i + 2) {
    \\  select  the page, then find all text frames in that page,  then align right
  }
}

any help is appreciated.任何帮助表示赞赏。 thank you.谢谢你。

Here is a simplest solution:这是一个最简单的解决方案:

var pages = app.activeDocument.pages;

for (var i = 1; i < pages.length; i = i + 2) {
    app.select(pages[i].textFrames);
    try {
        app.menuActions.item("$ID/Horizontal Page Align Left").invoke()
    } catch(e) {}
}

It relies on selection objects and invoke the menu action.它依赖于选择对象并调用菜单操作。 Sometimes this is not the best idea (that is why try/catch ).有时这不是最好的主意(这就是为什么try/catch )。 The solution can be more complicated and robust.该解决方案可以更加复杂和稳健。 It depends on your limitations and additional details.这取决于您的限制和其他详细信息。

Update更新

I didn't get that you need to align CONTENT of the frames rather than the frames.我不知道您需要对齐框架的内容而不是框架。 It can be done, but the solution differs for linked and non-linked text frames.可以做到,但链接和非链接文本框架的解决方案不同。 Except when one paragraph belongs two neighboring pages.除非一个段落属于两个相邻的页面。

To get all of the frames on a page:要获取页面上的所有框架:

var myFrames = myDocument.pages[i].textFrames;

Then you can loop through the frames and their paragraphs and apply (use different counter variables, eg "c" and "b")然后,您可以遍历框架及其段落并应用(使用不同的计数器变量,例如“c”和“b”)

myFrames[c].paragraphs[b].justification = Justification.RIGHT_ALIGN;

You can also try everyItem()你也可以试试everyItem()

myDocument.pages[i].textFrames.everyItem().paragraphs.everyItem().justification = Justification.RIGHT_ALIGN;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM