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

Change applied language in anchored boxes

Engaged ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

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

Views

252

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

...

Votes

Translate

Translate
Community Expert ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

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

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

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

Copy link to clipboard

Copied

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

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

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

Copy link to clipboard

Copied

Hi @Robert Tkaczyk thank you.

This worked

myDoc.stories.everyItem().text[0].appliedLanguage = app.languagesWithVendors[3];

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

Copy link to clipboard

Copied

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;

 

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

Copy link to clipboard

Copied

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

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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) {}  

 

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

Copy link to clipboard

Copied

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

 

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

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

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