Skip to main content
Inspiring
April 21, 2011
Answered

[JS IDCS5] Running through all tables and place textFrame

  • April 21, 2011
  • 1 reply
  • 2105 views

I wan't to place textFrames below all the tables within a document.

#target indesign;

var myDocument = app.activeDocument;
var myTables = myDocument.stories.everyItem().tables;

for(var i=myTables.length-1; i>=0; i--){

           // var myFrame = myTables.insertionPoints[0].textFrames.add();

           // the above line does not work......
    }

How do I get the insertionPoints of the tables, so textFrames can be added at that point?

Regards, Sjoerd

This topic has been closed for replies.
Correct answer Peter Kahrel
myIP = myTables.storyOffset;
myIP.parentStory.insertionPoints[myIP.index+1].textFrames.add();
JavaScript Error!

Error Number: 21
Error String: undefined is not an object

Engine: main
Source: myTable.parentStory.insertionPoints[0].textFrames.add();

This is the error now!? Is there something wrong with the first part of my script?


> Is there something wrong with the first part of my script?

Looks like it. Your second line needs to be as in the script below. The difference is that in your version a collection is made, while in the below version, the script creates an array. I would have thought that a collection should have worked as well, but in this case it doesn't.

var myDocument = app.activeDocument;
var myTables = myDocument.stories.everyItem().tables.everyItem().getElements();

var myIP, myFrame;
for (var i=myTables.length-1; i>=0; i--){
   myIP = myTables.storyOffset;
   myFrame = myIP.parentStory.insertionPoints[myIP.index+1].textFrames.add();
   }

Peter

1 reply

Peter Kahrel
Community Expert
Community Expert
April 21, 2011

Tables have a property storyOffset, which is an insertion point. myTable.storyOffset is the insertion point immediately before the table. The ip after the table you can get your hands on like this:

myTable.storyOffset.parentStory.insertionPoints[myTable.storyOffset.index+1];

Peter

stoereeeAuthor
Inspiring
April 21, 2011

Tables have a property storyOffset, which is an insertion point. myTable.storyOffset is the insertion point immediately before the table. The ip after the table you can get your hands on like this:

myTable.storyOffset.parentStory.insertionPoints[myTable.storyOffset.in dex+1];

Now I get the following error:

JavaScript Error!

Error Number: 55

Error String: Object does not support the property er method 'storyOffset'

Engine: main

Source: myTables.storyOffset.parentStory.insertionPoints[0].textFrames.add();

What is wrong?

Peter Kahrel
Community Expert
Community Expert
April 21, 2011

> What's wrong?

This:

myTables.storyOffset.parentStory.insertionPoints[myTables.storyOffset.index+1].textFrames.add();

It might be more convenient to split that line as follows:


myIP = myTables.storyOffset;
myIP.parentStory.insertionPoints[myIP.index+1].textFrames.add();

Peter