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

Story.textFrames[0] is not valid

Engaged ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Hi everyone,

I'm a little confused about what's happening in my script.

I've split the stories in my document into different arrays depending on their appliedLanguage.

I then have a function that loops through the arrays and searches the contents for a specific phrase.

If the story contains the phrase I am trying to alert:

story.textFrames[0].parentPage

However

story.textFrames[0].isValid

returns false.

So instead I alert:

story.textContainers[0].constructor.name

which gives me TextFrame.

I then alert:

story.textContainers[0].parentPage

which gives me a page object.

Why does Story.textFrames[0] not exist?

Thanks

TOPICS
Scripting

Views

1.7K

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 1 Correct answer

Community Expert , May 22, 2017 May 22, 2017

jakec88782761  wrote

Why does Story.textFrames[0] not exist?

Thanks

Hi Jake,

because with that you address the first anchored text frame in the story.
And that might not exist.

Stories can flow through text frames and text paths.
Text containers are arrays that can contain both kind of objects.

Regards,
Uwe

Votes

Translate

Translate
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

jakec88782761  wrote

Why does Story.textFrames[0] not exist?

Thanks

Hi Jake,

because with that you address the first anchored text frame in the story.
And that might not exist.

Stories can flow through text frames and text paths.
Text containers are arrays that can contain both kind of objects.

Regards,
Uwe

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 ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

To make it more clear:
Have a document with one text frame where a text frame is anchored to.

Now run this code:

var story = app.documents[0].stories[0];

$.writeln(story.id+"\t"+"story.id");

$.writeln(story.textContainers[0].parentStory.id+"\t"+"story.textContainers[0].parentStory.id");

$.writeln(story.textFrames[0].parentStory.id+"\t"+"story.textFrames[0].parentStory.id");

The result should be something like this:

211    story.id

211    story.textContainers[0].parentStory.id

241    story.textFrames[0].parentStory.id

Your ID numbers may be different, but the ID number in the first two lines are identical.

In line 3 of the results you see a different story. The story that is constituted with the anchored text frame.

Regards,
Uwe

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 Beginner ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Return error when performing fourth line "object is invalid", why?

(執行第四行時回報錯誤"物件無效",為什麼?。)

  留言

To make it more clear:
Have a document with one text frame where a text frame is anchored to.

Now run this code:

var story = app.documents[0].stories[0]; $.writeln(story.id+"\t"+"story.id"); $.writeln(story.textContainers[0].parentStory.id+"\t"+"story.textContainers[0].parentStory.id"); $.writeln(story.textFrames[0].parentStory.id+"\t"+"story.textFrames[0].parentStory.id");

The result should be something like this:

211    story.id 211    story.textContainers[0].parentStory.id 241    story.textFrames[0].parentStory.id

Your ID numbers may be different, but the ID number in the first two lines are identical.

In line 3 of the results you see a different story. The story that is constituted with the anchored text frame.

Regards,
Uwe

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 ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

I assume:

Because you have no text frame anchored in your story.


Try this with a new document where there is one text frame and another one that is anchored to the text of that text frame.
Put nothing else in that document.

IMPORTANT EDIT:

1. Make sure that you first add the text frame that stands alone.
2. Then add the text frame you like to anchor.
3. Then anchor the text frame you last build.

Reason:
In line 1 of the script we address the story with index number 0 .

That's the first story in time added to the document.
And that belongs to the first text frame you added to the document.

So if you anchored the first text frame to the last text frame you did, you addressed the story of the anchored text frame with variable story.

You also could do the following:

Select the text frame where the other one is anchored to and change line 1 of the snippet to:

var story = app.selection[0].parentStory;

Sorry for this inconvenience…

Regards,
Uwe

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 Beginner ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

You are right, I missed the anchor this step.

(你是對的,我漏了錨定這一步。)

This is my result:

(這是我的結果:)

var story = app.documents[0].stories[0]; 

$.writeln(story.id+"\t"+"story.id"); 

$.writeln(story.textContainers[0].parentStory.id+"\t"+"story.textContainers[0].parentStory.id"); 

$.writeln(story.textFrames[0].parentStory.id+"\t"+"story.textFrames[0].parentStory.id"); 

var myTextFrame = app.documents[0].textFrames[0]

$.writeln(myTextFrame.id+"\t"+"myTextFrame.id"); 

$.writeln(myTextFrame.parentStory.textContainers[0].id+"\t"+"myTextFrame.parentStory.textContainers[0].id"); 

$.writeln(myTextFrame.parentStory.textFrames[0].id+"\t"+"myTextFrame.parentStory.textFrame.id"); 

250    story.id

250    story.textContainers[0].parentStory.id

277    story.textFrames[0].parentStory.id

270    myTextFrame.id

270    myTextFrame.parentStory.textContainers[0].id

274    myTextFrame.parentStory.textFrame.id

Thank you

(謝謝)

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
Engaged ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Hi Uwe,

What's the difference between a text frame and a text path?

My story is not anchored, but my confusion was that textFrames[0] returns invalid and textContainers[0] returns text frame.

So there is a text frame but it's hidden inside a text container?

Thanks for your reply.

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 ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Hm…
How should I explain that better?

Let's try this:
All text frames and text paths where a story can flow through are stored only in:
Story.textContainers

All text frames that are anchored to the story are stored in:
Story.textFrames

What a text path is?
Use the text path tool in InDesign's UI that is available by the flighout menu of the text tool.


You could add a text path to any drawn path on the page.
It is a path where you can type text into.

You could even add a text path to a text frame. So technically this text frame is addressing two stories:
textFrame.parentStory
textFrame.textPaths[0].parentStory

So you see a text path like this has a parentStory which is a normal Story object. You also would be able to thread text frames with text paths and create a story with a textContainers array, that will not only hold text frame objects but also text path objects.

Regards,
Uwe

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
Engaged ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Thank you Uwe,

I think I understand the underlying structure now.

So an "anchored text frame" is a text frame which does not contain a story that flows into other text frames?

This was a great explanation of textContainers

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 ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

LATEST

jakec88782761  wrote

… So an "anchored text frame" is a text frame which does not contain a story that flows into other text frames?

Not quite 😉

When working in the UI, yes:
An anchored text frame cannot be part of a story that has more than one textContainers.


By scripting one could do a story with several textContainers that are all anchored to different parts of a story.

But that's another story… 🙂


And is not recommended. And a construction like that has its downside.
Problems with an IDML roundtrip if I recall right.
And perhaps stability problems.

Regards,
Uwe

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