質問

Here's a conundrum I've discovered.

I have a script that opens a file in InDesign, does some work to it, then closes it. To help speed it up, I have turned off displaying the file by using the false argument while opening the file, like so:

var document = app.open(oFile, false);

Sometimes, while doing some work on an open file, the script may need to need to resize a certain page from 11 inches tall to 12.5 inches tall, thusly:

    if (padPrinted) {
        for (var p = 0; p < outputRangeArray.length; p++) {
            var padPage = document.pages.item(outputRangeArray[p]);
            if (padPage.bounds[2] - padPage.bounds[0] === 11) {
                padPage.select();
                var myY1 = padPage.bounds[0] -= 0.75;
                var myX1 = padPage.bounds[1];
                var myY2 = padPage.bounds[2] += 0.75;
                var myX2 = padPage.bounds[3];
                padPage.reframe(CoordinateSpaces.INNER_COORDINATES, [[myX1*72, myY1*72], [myX2*72, myY2*72]]);
            }
        }
    }

This has been working flawlessly for me for quite some time, but now it sometimes errors on the line padPage.select() with the message:

No document windows are open.

If I go back to the line which opens the file and delete the false argument, then the script works fine.

So, I'd like to know if there's any way to get around this. I'd like to have the documents open without displaying them, but still have the ability to resize a page when I need to. Any ideas?

役に立ちましたか?

解決

Why do you call padPage.select();? It doesn't look like your code needs it.

Edit:

On page to page 42 of the Adobe InDesign CS6 Scripting Guide: Javascript, there is a sample snippet that reframes the page and doesn't call select(). The snippet comes from a sample script in the InDesign CS6 Scripting SDK (scroll to the bottom).

The path of the sample script is Adobe InDesign CS6 Scripting SDK\indesign\scriptingguide\scripts\JavaScript\documents\PageReframe.jsx

Inspecting this script, we see that it never calls select(). In fact, the PageResize.jsx never calls select() either.

Also, while InDesign Server can resize and reframe pages, you'll notice that the select() function is missing entirely. It would seem that select() affects only the GUI.

In the face of all this evidence, I would wager that the scripting guide is wrong when it says "you must select the page". Try removing that line and see if it works.

Edit 2

On an unrelated note, the following lines might be troublesome:

var myY1 = padPage.bounds[0] -= 0.75;
var myX1 = padPage.bounds[1];
var myY2 = padPage.bounds[2] += 0.75;

The += and -= operators will attempt to modify the bounds directly, but the bounds are read-only and can only be modified with methods such as resize or reframe. I would recommend changing it to this:

var myY1 = padPage.bounds[0] - 0.75;
var myX1 = padPage.bounds[1];
var myY2 = padPage.bounds[2] + 0.75;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top