Copy link to clipboard
Copied
Hi,
I have 3 textframes in InDesign. I am trying to thread them using a script. Currently I am working on only one page but in future there might me multiple pages.
I have written a script to thread the textframe, however, I am not able to understand how it is working.
Here is the code:
var myDoc = app.documents[0];
var myFrames = myDoc.textFrames;
for(i=1;i<myFrames.length;i++){
myFrames[i].previousTextFrame = myFrames[i-1];
}
I took this code from somewhere, I mean the previousTextFrame line and fail to understand how it is working. Ideally should'nt it be the the next frame ?
Another question is that when I put some data in the text frame before threading, why is it starting from the last textframe.
Here is the code which I wrote to put data in the textframe without threading:
var myDoc = app.documents[0];
var myFrames = myDoc.textFrames;
//alert(myFrames.length);
for(i=0;i<myFrames.length;i++){
myFrames[i].contents = "Data: " + i;
}
I also tried reversing then the code is not working at all. Here is the reversed code:
var myDoc = app.documents[0];
var myFrames = myDoc.textFrames;
for(i=myFrames.length; i> 0;i--){
myFrames[i].contents = "Data: " + i;
}
Can anyone shed some light on this. Thanks.
I took this code from somewhere, I mean the previousTextFrame line
Hi @shahidr100 , to illustrate @Peter Kahrel ’s post, I added these 3 text frames to the page from top to bottom, so the bottom frame is myFrames[0] and the top frame is myFrames[1]:
The script below does this:
var myDoc = app.documents[0];
//the myFrames array. Newly added frames get added to the beginning of the array.
//myFrames[0] is the most recent frame added to the document
var myFrames = myDoc.textFrames.ever
> Meaning previousTextFrame and nextTextFrame, both can be used for threading. Its a matter of choice.
Yes. A.nextTextFrame = B and B.previousTextFrame = Aare equivalent. Which one you choose to use depends on the circumstances.
> Can I place the text in last index first and then come to index 0? I tried that and it did not work.
I'm not sure what you mean here or what you're after. When you thread several frames you end up with one story. So even if you then place som text in the last f
...Copy link to clipboard
Copied
> the previousTextFrame line and fail to understand how it is working
By using previousTextFrame (nextTextFrame) you tell InDesign to thread the two frames. That's all there's to it.
> why is it starting from the last textframe.
When you place some text frames on a page, the last one you place has index 0. That's just how it works.
Copy link to clipboard
Copied
I took this code from somewhere, I mean the previousTextFrame line
Hi @shahidr100 , to illustrate @Peter Kahrel ’s post, I added these 3 text frames to the page from top to bottom, so the bottom frame is myFrames[0] and the top frame is myFrames[1]:
The script below does this:
var myDoc = app.documents[0];
//the myFrames array. Newly added frames get added to the beginning of the array.
//myFrames[0] is the most recent frame added to the document
var myFrames = myDoc.textFrames.everyItem().getElements();
for(i=1;i<myFrames.length;i++){
myFrames[i].nextTextFrame = myFrames[i-1]
}
Copy link to clipboard
Copied
@rob day @Peter Kahrel Thanks.
>By using previousTextFrame (nextTextFrame) you tell InDesign to thread the two frames. That's all there's to it.
Meaning previousTextFrame and nextTextFrame, both can be used for threading. Its a matter of choice.
>When you place some text frames on a page, the last one you place has index 0. That's just how it works.
Can I place the text in last index first and then come to index 0? I tried that and it did not work. I have pasted the code in my original post above.
Actually I am trying to polish indesign programming skills and I have decided to start with textFrame object. Also there are so many ways to get handle to textframe which is again confusing. I know just one method ---- myFrames = myDoc.textFrames;
Now this one I am not able to understand:
myFrames = myDoc.textFrames.everyItem().getElements();
Thanks
Copy link to clipboard
Copied
> Meaning previousTextFrame and nextTextFrame, both can be used for threading. Its a matter of choice.
Yes. A.nextTextFrame = B and B.previousTextFrame = Aare equivalent. Which one you choose to use depends on the circumstances.
> Can I place the text in last index first and then come to index 0? I tried that and it did not work.
I'm not sure what you mean here or what you're after. When you thread several frames you end up with one story. So even if you then place som text in the last frame, it will end up in the first frame, which has the beginning of the story.
> Actually I am trying to polish indesign programming skills and I have decided to start with textFrame object.
Excellent choice!
myFrames = myDoc.textFrames;
This creates a collection. And
myFrames = myDoc.textFrames.everyItem().getElements();
creates an array. The difference is significant. Arrays process much more quickly than collections. But sometimes using a collection is more convenient. Marc Autret wrote up the technical details here: https://www.indiscripts.com/post/2010/06/on-everyitem-part-1
P.
Copy link to clipboard
Copied
@Peter Kahrel Thank you so much.