简体   繁体   中英

inDesign scripting “Object is invalid”

I'm trying to set height & insets for the first row of a table one way, and then all following rows to another set of values.

I'm receiving a JavaScript error message when I run it:

Error Number:45
Error String: Object is invalid

Engine: main
File: C:\...
Line: 49
Source: app.activeDocument.stories.everyItem().tables.everyItem().rows[x].height = ".12 in";

Not sure where to go from here? Here is a pastebin of my current script http://pastebin.com/iUXgPZSM

The everyItem() method doesn't always work in every context. In this case, it doesn't work because you're setting an attribute, eg. height = ".12 in" . It you get the elements first using getElements() and then loop through them, it will work.

Also, note that you can't make the height of the rows smaller than the text size. InDesign just won't do it. In the example I provide I used 1 in since the .12 in appeared to be smaller than the default text size.

Finally, I had a look at your pastebin script and you could probably clean it up a little bit by using variables instead of chains of functions. It might take up more "vertical space" but in the end it is more readable for other people.

var doc = app.activeDocument;

var everyStory = doc.stories.everyItem();
var everyTable = everyStory.tables.everyItem();
var allRows = everyTable.rows.everyItem().getElements();

for (var i=1, l=allRows.length; i < l; i++) {
   var row = allRows[i];
   row.height = "1 in";
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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