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

Change applied language in anchored boxes

Engaged ,
Oct 05, 2023 Oct 05, 2023
Hi All,
This is a part of the script where I have been trying to change the applied language in a document to all textFrames to Swiss German. It is working fine but no changes in anchored textFrames.
Any suggestion please.
 
var myDoc = app.activeDocument;
myDoc.textFrames.everyItem().text[0].appliedLanguage = app.languagesWithVendors[3];
 
Regards
Virender
 
TOPICS
Scripting
1.0K
Translate
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

LEGEND , Oct 05, 2023 Oct 05, 2023

Anchored TextFrames are not directly listed in the Document - you would have to add one more level of everyItem():

 

myDoc.textFrames.everyItem().texts[0].textFrames.everyItem().texts[0].appliedLanguage = app.languagesWithVendors[3];

 

or something like that - I'm not JS guy so if it won't work - you'll have to wait for JS Gurus.

 

But why are you processing TextFrames - and not Stories?

 

Should work much faster - every TextFrame ALWAYS have parentStory - can't exists WITHOUT - and if Story hav

...
Translate
LEGEND ,
Oct 05, 2023 Oct 05, 2023

Anchored TextFrames are not directly listed in the Document - you would have to add one more level of everyItem():

 

myDoc.textFrames.everyItem().texts[0].textFrames.everyItem().texts[0].appliedLanguage = app.languagesWithVendors[3];

 

or something like that - I'm not JS guy so if it won't work - you'll have to wait for JS Gurus.

 

But why are you processing TextFrames - and not Stories?

 

Should work much faster - every TextFrame ALWAYS have parentStory - can't exists WITHOUT - and if Story have multiple TextContainers = TextFrames - do not confuse with Anchored / InLine TextFrames and other objects  - then you'll refer to the contents of all of those containers only once.

 

BUT - why can't you just modify ParaStyles? If you have them correctly applied of course ...

 

Translate
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
LEGEND ,
Oct 05, 2023 Oct 05, 2023

And I'm pretty sure should be texts[] ?

 

texts

Texts Text

readonly

A collection of text objects.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Story.html

 

Translate
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 ,
Oct 05, 2023 Oct 05, 2023

Hi @Robert at ID-Tasker thank you.

This worked

myDoc.stories.everyItem().text[0].appliedLanguage = app.languagesWithVendors[3];
Translate
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 ,
Oct 05, 2023 Oct 05, 2023

Hi @virender_CTS , Also, you might want to get all of the texts, and if you want to be sure about the language use itemByName (I get Hindu when I use item 3)

 

 

var lang = app.languagesWithVendors.itemByName("German: Swiss");
var s = app.activeDocument.stories.everyItem().texts.everyItem().appliedLanguage = lang;

 

Translate
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
LEGEND ,
Oct 05, 2023 Oct 05, 2023
quote

[...] you might want to get all of the texts, [...]

By @rob day

 

Out of curiosity - how can there be more than one Text in Texts collection??

 

Translate
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 ,
Oct 05, 2023 Oct 05, 2023

Can’t think of a way, but the object model implies there is.

Translate
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
LEGEND ,
Oct 05, 2023 Oct 05, 2023

Then maybe done this way "just in case"? 

 

It wouldn't be such a bad thing if it would automatically list / return references to texts from all anchored "objects" - TextFrames or Foot- / End-Notes - or even Hyperlinks / Bookmarks / Cross-Refs - in the order of appearance - as all those things are available in their own collections anyway...

 

Translate
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 ,
Oct 05, 2023 Oct 05, 2023

Noted, will check with my colleagues and change to itemByName.

Translate
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 ,
Oct 05, 2023 Oct 05, 2023
LATEST

Actually, I don’t think you need texts—a story has an applied language property:

 

This would get all stories as well as table cells:

 

var lang = app.languagesWithVendors.itemByName("German: Swiss");
app.activeDocument.stories.everyItem().appliedLanguage = lang;

//get table texts if they exist
try {
    app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().texts.everyItem().appliedLanguage = lang;
}catch(e) {}  

 

Translate
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
LEGEND ,
Oct 05, 2023 Oct 05, 2023

But it can't ?? And just checked - you need to use texts[0].

 

Or as per @rob day example - just texts without [].

 

Translate
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