• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Textframe threading script in Indesign

Enthusiast ,
Aug 20, 2024 Aug 20, 2024

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.

TOPICS
Scripting

Views

327

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Aug 20, 2024 Aug 20, 2024

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]:

 

Screen Shot 7.png

 

The script below does this:

 

Screen Shot 8.png

 

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
...

Votes

Translate

Translate
Community Expert , Aug 21, 2024 Aug 21, 2024

> 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

...

Votes

Translate

Translate
Community Expert ,
Aug 20, 2024 Aug 20, 2024

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

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]:

 

Screen Shot 7.png

 

The script below does this:

 

Screen Shot 8.png

 

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]
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2024 Aug 20, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2024 Aug 21, 2024

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 21, 2024 Aug 21, 2024

Copy link to clipboard

Copied

LATEST

@Peter Kahrel Thank you so much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines