I have got problem with TextFrames and Stories in InDesign. So, I am executing this script:
var myFrame = app.selection;
var myStory = myFrame.parentStory;
myID = myStory.id;
alert("Sel: " + myID);
alert("Story id: " + myStory.textFrames.length);
First of all I'm getting handle to selected textFrame, then I am getiing handle and ID of Story, which contain this textFrame. Everything here works fine and we get here proper Story ID. But, when I execute the last line, I always get length=0. Why? If I selected a textFrame, which is a part of the story (I got the parentStroy attibute), the "length" in the last line should be always at least 1. But this is 0. I cannot understand why.
So, how can I get all textFrames which belong to the story? I could admit, that when I execute this line:
the content of the textFrame is put to file (like expected)....
Probably because you're using CS3 or CS4. In these versions of InDesign, the Story.textFrames collection is the collection of text frames that are inline or anchored to the story.
What you are interested in is the textContainers property (which is an array, by the way, so be careful about addressing the last member; you have to use: myStory.textContainers[myStory.textContainers.length - 1]).
Actually, you can use:
which is a clearly anachronistic name for what should now be called endTextContainer. This is less typing, but takes twice as long because it involves two calls to the object model.