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

Underline the last word found in a particular paragraph

Community Beginner ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

I have a problem.

When I use Grep expression to find a specific word, the whole word is searched based on the story.

But the word I'm looking for is a specific word at the end of the paragraph.

I want to underline the character style only in the last word of the whole paragraph.

I want to know how to implement with Grep expressions or scripts.

For example,

I have a dream.

I have a dream. I have a dream.

I have a dream. I have a dream. I have a dream, too.

I have a dream. I have a dream. I have a dream, too. Dream come true.

TOPICS
Scripting

Views

1.3K

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

Advocate , Sep 15, 2018 Sep 15, 2018

Just on condition before finding text in that paragraph, Just like this,

var myDoc = app.documents[0];

var myFrame = myDoc.pages[0].textFrames[0];

var para = myFrame.paragraphs;

var myFindingWords = ["아닌", "없는"];

for(var m = 0; m < myFindingWords.length; m++){

    for(var i = 0; i < para.length; i++){

//Test Your para style here

        if(para.appliedParagraphStyle.name.toString() == "TestParagraphStyle"){

            var myWord = null;

            var words = para.words;

            for(var j = 0; j < wo

...

Votes

Translate

Translate
Advocate ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

you can try this without grep if you want to.

var myDoc = app.documents[0];

var myFrame = myDoc.pages[0].textFrames[0];

var para = myFrame.paragraphs;

for(var i = 0; i < para.length; i++){

    var myWord = null;

    var words = para.words;

    for(var j = 0; j < words.length; j++){

        if(words.contents.toString().toLowerCase().indexOf("dream") != -1){

            myWord = words;

            }

        }

    if(myWord != null){

        myWord.underline = true;

        }

    }

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 ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

Very good.

I appreciate your solution.

However, the example above was made in English to help you understand.

"dream" with examples in English apply well.

But the language I use is East Asia.

I want to find the words made in China, Korea, Japan language as the above question.

For example, it might be expressed here,

not | wrong | wrong

In Korean, it is as follows.

아닌 | 틀린 | 잘못된

My aim is to underline the word that is located at the end of the paragraph when these words overlap in a paragraph.

I want to know if this language case of CJK culture is possible.

Thank you in advance.

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
Advocate ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

So you can try this, You just Need to add your text in your array.

var myDoc = app.documents[0];

var myFrame = myDoc.pages[0].textFrames[0];

var para = myFrame.paragraphs;

var myFindingWords = ["dream", "test", "test1"];

for(var m = 0; m < myFindingWords.length; m++){

    for(var i = 0; i < para.length; i++){

        var myWord = null;

        var words = para.words;

        for(var j = 0; j < words.length; j++){

            var myWordFind = myFindingWords.toLowerCase();

            if(words.contents.toString().toLowerCase().indexOf(myWordFind) != -1){

                myWord = words;

                }

            }

        if(myWord != null){

            myWord.underline = true;

            }

        }

    }

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

As you mentioned, I put "아닌" in test1 and "없는" in test2.

But it did not work.

I wonder if word object does not apply in 2byte language.

I also attach an image file of what I am about to replace. The red underline is the part you want to replace.image1.png

var myDoc = app.documents[0]; 

var myFrame = myDoc.pages[0].textFrames[0]; 

var para = myFrame.paragraphs; 

var myFindingWords = ["아닌", "없는"]; 

for(var m = 0; m < myFindingWords.length; m++){ 

    for(var i = 0; i < para.length; i++){ 

        var myWord = null; 

        var words = para.words; 

        for(var j = 0; j < words.length; j++){ 

            var myWordFind = myFindingWords.toLowerCase(); 

            if(words.contents.toString().toLowerCase().indexOf(myWordFind) != -1){ 

                myWord = words

                } 

            } 

        if(myWord != null){ 

            myWord.underline = true; 

            } 

        } 

    }

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
Advocate ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

This is working properly in my system.

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

Really?

It is strange that I do not work on my computer.

On the ExtendScript Toolkit screen, the result is "Execution finished: Result: undefined".

Does my Indesign have a problem?

image2.png

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
Advocate ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

"Execution:finished" doesn't mean that there is an error.

Can you share your indesign file with some of those string?

So that I can have a loot at it?

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

I replaced it with another string and made it a sentence.

If you follow the link you will get the inDesign shared file.

Please solve my problem.

https://www.dropbox.com/s/p6xhgf8ralghtmb/test_modified.zip?dl=0

I added the used fonts. And inDesign was packaged.

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
Advocate ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

Code has worked in my system on your provided file.

I don't find any error!

Only one character has match and it is underlined!

Capture.JPG

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

Thank you.

I'll have to reinstall my program once.

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

I deleted the Indesign korean version and installed the English version.

Then it worked the same as you were successful.

The program may or may not be applied according to the language of each country.

This seems to be an official question to the Adobe company.

I am grateful for your efforts to solve the problem.

Thank you so much.

ps.

In addition, I ask you one more question.

I wanted a way to underline only word in a particular paragraph.

So please let me know how to find this in a paragraph with a paragraph style named "AA" rather than an entire paragraph.

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
Advocate ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

Just on condition before finding text in that paragraph, Just like this,

var myDoc = app.documents[0];

var myFrame = myDoc.pages[0].textFrames[0];

var para = myFrame.paragraphs;

var myFindingWords = ["아닌", "없는"];

for(var m = 0; m < myFindingWords.length; m++){

    for(var i = 0; i < para.length; i++){

//Test Your para style here

        if(para.appliedParagraphStyle.name.toString() == "TestParagraphStyle"){

            var myWord = null;

            var words = para.words;

            for(var j = 0; j < words.length; j++){

                var myWordFind = myFindingWords.toLowerCase();

                if(words.contents.toString().toLowerCase().indexOf(myWordFind) != -1){

                    myWord = words;

                    }

                }

            if(myWord != null){

                myWord.underline = true;

                }

            }

        }

    }

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 ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

Your solution works very well.

This is the best answer.

Thank you once again for your sincerity!!

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 ,
Sep 16, 2018 Sep 16, 2018

Copy link to clipboard

Copied

Hi Yadav,

Interested by your code, I've tested it! …

[Why limit the research to one text frame on the first page?]

Targets: "dream" and "cloud"

Using your last code:

Capture d’écran 2018-09-16 à 22.39.16.png

Mine:

Capture d’écran 2018-09-16 à 22.39.47.png

Grep seems to me simpler to code and mostly more efficient! …

// by FRIdNGE [September 2018]

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Underlinings! …");

function main()

    {

        // ---------------------------------------------------------------------------------------------------

        var myTargets = ["dream","cloud"], // To be completed! …

        myPStyle = "TestParagraphStyle", // Name of the Para Style

        myCStyle = "Underlining", // Name of the Char Style

        // ---------------------------------------------------------------------------------------------------

        T = myTargets.length,  t;

        app.findGrepPreferences = app.changeGrepPreferences = null;

        for ( t = 0; t < T; t++ ) {

            app.findGrepPreferences.findWhat = "(?i)(\\b" + myTargets + "\\b)(?!.+\\b\\1\\b.*)";

            app.findGrepPreferences.appliedParagraphStyle = myPStyle;

            app.changeGrepPreferences.appliedCharacterStyle = myCStyle;

            app.activeDocument.changeGrep();

        }

        app.findGrepPreferences = app.changeGrepPreferences = null;

        alert("Done! …  ;-)\rby FRIdNGE [September 2018]")

    }

Best,

Michel, for FRIdNGE

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
Advocate ,
Sep 16, 2018 Sep 16, 2018

Copy link to clipboard

Copied

LATEST

Nice

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