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

How to add Chinese Pinyin in the script?

Community Beginner ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

I spent a day to search the way to add Chinese Pinyin in scripting. But found nothing.

 

I have a lot of words to set to topics. So I have to select the words, then make the words setting to topics. Topics are sorted by Chinese Pinyin. When I do it manually, the Chinese Pinyin of target words come out automatically. See the picture below.

Snipaste_2021-12-23_17-43-48.png

There are too many words to set topics. So I write a Javascript.

 

Here is the code:

for(c1 = 0; c1 < myTargetWordsToInsertIndex.length; c1++){
app.select(myTargetWordsToInsertIndex[c1]);

app.activeDocument.indexes[0].topics.add(app.selection[0].contents, app.selection[0].contents's Chinese Pinyin);
}

It's just the app.selection[0].contents's Chinese Pinyin, I can't find any information about it in the Object Model Viewer. 

 

Is there anyone knows some info about this?

 

Thanks for your attention.

TOPICS
Scripting

Views

741

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

Advisor , Dec 24, 2021 Dec 24, 2021

Hello @Dargon Kong,

 

Try the snippet below and report back on what happens...

You'll have to add it to the rest of your code.

 

 

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

for(c1 = 0; c1 < myTargetWordsToInsertIndex.length; c1++){
    app.select(myTargetWordsToInsertIndex[c1]);
    app.menuActions.itemByID(78142).invoke()

}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

 

 

Regards,

Mike

Votes

Translate

Translate
Advisor ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Hello @Dargon Kong,

 

It's not real clear what you are trying to do but you can try changing the last line in your code to this.

 app.activeDocument.indexes.add().topics.add({name: app.selection[0].contents});

 

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

 

Regards,

Mike

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Topics.add (name: string , sortBy: string , withProperties: Object )

The Parameter “sortBy: string“, is there a way to call its corresponding string through a property or a variable?

 

Cause I input the words "文字" manually in Indesign, the Chinese Pinyin "WEN2,04;ZI4,06" will be created by Indesign Program itself.

Snipaste_2021-12-24_00-47-55.png

 

So as for the Javascript, I think there is maybe a property or a variable corresponding to the sortBy: string of app.selection[0].contents.

 

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
Advisor ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Hello @Dargon Kong,

 

Take a look here pages 154 - 157 might give you some direction, also look at https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#IndexingSortOption.html

 

Regards,

Mike

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 ,
Dec 24, 2021 Dec 24, 2021

Copy link to clipboard

Copied

OK. Thanks. I will try something else.

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
Guide ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

When I search an own OMV for Pinyin, the only reference is an enumeration HeaderTypes.CHINESE_PINYIN that would be assigned to app/doc.indexingSortOptions.headerType .

Do you already set that value?

 

At the plug-in side, there is a similar GroupOrder, but beyond that I only see some Pinyin related dialog - is a concept called "Tone" relevant here?

 

Anyway, short from looking what actually happens under the hood - even with an example document that would take hours - a feature to transliterate to Pinyin is likely only implemented in the UI. I'd either have a look at UI scripting using AutoHotkey, or alternatively perform the task via an outside service - e.g. export the topic name, process it in node.js with Pinyin support via ICU transforms (I'd guess InDesign uses the same), then supply the sort order entries from the result. Maybe CEP has a matching ICU subsystem so you can stay within InDesign? As I don't use CEP, someone else would have to answer that.

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 ,
Dec 24, 2021 Dec 24, 2021

Copy link to clipboard

Copied

I have tried "Tone" or "diacritics" and so on before.

It seems like I have to solve this problem outside Indesign Javascript.

I will try using Autohotkey. Much more easier.

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
Advisor ,
Dec 24, 2021 Dec 24, 2021

Copy link to clipboard

Copied

Hello @Dargon Kong,

 

Try the snippet below and report back on what happens...

You'll have to add it to the rest of your code.

 

 

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

for(c1 = 0; c1 < myTargetWordsToInsertIndex.length; c1++){
    app.select(myTargetWordsToInsertIndex[c1]);
    app.menuActions.itemByID(78142).invoke()

}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

 

 

Regards,

Mike

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 ,
Dec 24, 2021 Dec 24, 2021

Copy link to clipboard

Copied

LATEST

Excellent. I never think of a solution like this. Let Indesign do the job. 

I really appreciate it. Thanks a million. ^_^

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