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

Find and Replace Font - Redefine styles when changing all

Contributor ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

Hi,

     I need to enable the checkbox "Redefine Style When Changing All" in Find Font dialog.  How can I enable this check box when replacing fonts??

Screen shot 2017-09-19 at 1.34.49 PM.png

- Sudha K

TOPICS
Scripting

Views

7.6K

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
Guru ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

As far as I know, this button has no relative property in scripting. However, there's a workaround: you can achieve the same effect by breaking it into three steps.

Find-replace a font

  1. in all paragraph styles
  2. in all character styles
  3. in locally formatted text

Here's a script that uses this approach.

Hope this helps.

— Kas

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
Contributor ,
Oct 05, 2017 Oct 05, 2017

Copy link to clipboard

Copied

Hi,

     Sorry for late reply...

     Thanks it is useful to me...   But when I am checking this with manually, i have confused...

    1. Actual function of "Redefine Styles When Changing All"  in Find Font Menu.

     2. What is the difference between "Redefine Styles When Changing All"  in Find Font Menu  &  the "Redefine Style in Paragraph Style Palete".

     3. I have used the below code. Font is applied for "#" but there is no character. Manually we can replace it. But using programatically its throwing "

Screen shot 2017-10-05 at 2.03.42 PM.png

    

- Sudha K

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
Guru ,
Oct 05, 2017 Oct 05, 2017

Copy link to clipboard

Copied

1. Actual function of "Redefine Styles When Changing All"  in Find Font Menu.

For example, you're replacing font A with font B.

If the "Redefine Styles When Changing All" is off, the font will be replaced as local formatting: in the styles it will remain defined as A, but in the text it will be overridden as B.

If the "Redefine Styles When Changing All" is on, in the styles it will be redefined as B.

2. What is the difference between "Redefine Styles When Changing All"  in Find Font Menu  &  the "Redefine Style in Paragraph Style Palete".

In the Find font dialog box, it finds one font in the whole document and replaces it with another one.

In the paragraph/character styles panel, you select some text, apply formatting -- e.g. choose another font, size, leading, etc. -- and by choosing Redefine style, you say InDesign: "I want the formatting of the applied style to be exactly the same as I just applied to the selected text".

3. I have used the below code. Font is applied for "#" but there is no character. Manually we can replace it. But using programatically its throwing "

You run some code that applied some formatting to some text in some document and something went somewhat wrong somewhere. Did I understand you correctly?

— Kas

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
Contributor ,
Oct 05, 2017 Oct 05, 2017

Copy link to clipboard

Copied

Hi,

     Thank you... Sorry forget to place the code...

     Yes.  I have used the below code to replace font in document.  It replaced but for some occurrences when the textframe applied that font but there is no character except "#".  In this case its throwing that error but it can be replaced manually. But in script its throwing the error.

Code:

var fFontName = "Helvetica Neue LT Std";

var fFontStyle = "77 Bold Condensed";

var rFontName = "Helvetica Neue";

var rFontStyle = "Condensed Bold";

var fObj = app.activeDocument;

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;          

app.findTextPreferences.appliedFont = fFontName;

app.findTextPreferences.fontStyle = fFontStyle;

app.changeTextPreferences.appliedFont  = rFontName;

app.changeTextPreferences.fontStyle  = rFontStyle;          

var res = fObj.findText();

alert(fFontName +  " - " + fFontStyle + " => " + rFontName + " - " + rFontStyle + "\n Res Count " + res.length);

if(res.length > 0)

{

    for(var rCnt = res.length - 1; rCnt >= 0 ; rCnt--)

    {

        var cRes1 = res[rCnt]; 

        cRes1.changeText();

      

    }

}

2. In a paragraph, i am changing font which is used in character style, after processing how can confirm whether its replaced correctly or not?? ie., font in parastyle or in character style??

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
Guru ,
Oct 05, 2017 Oct 05, 2017

Copy link to clipboard

Copied

Could you also provide a test file?

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
Contributor ,
Oct 05, 2017 Oct 05, 2017

Copy link to clipboard

Copied

I can attach jpg image or video file. Dono to attach file. So I have placing here as image.

Screen shot 2017-10-06 at 12.10.21 PM.png

     In the above image (Cursor Place), is applied some font (ie., Helvetical Nue LT Std 45 Light) .  Need to change that font to some other font (ie., Helvetica Neue Light).  Using find font, can able to replace. But using Find and Replace, could not able to find it.

    1.  I need to replace this occurrences of fonts in Indesign using Find and Replace option. Can we replace such occurrences using any other way???

     2. In the below url, font is replaced using styles, will it replace the fonts if it is used in No paragraph style?? Bcoz, we cant able to edit that style know.  In such cases how can we replace that font??

     Change fonts

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
Guru ,
Oct 06, 2017 Oct 06, 2017

Copy link to clipboard

Copied

Now I see what you mean.

Here's the code that works fore me.

var fontList = [

    ["Minion Pro\tRegular", "Myriad Pro\tRegular"]

];

   

main();

function main() {

    try { // if something goes wrong in the try-catch block, the batch processor won't stop here. It will log the error message and continue further

       

        var newFont, paragraphStyle, characterStyle,

        doc = app.activeDocument, // The frontmost document

        paragraphStyles = doc.allParagraphStyles,

        characterStyles = doc.allCharacterStyles;

       

        // Change in paragraph styles

        for (var p = 1; p < paragraphStyles.length; p++) {

            paragraphStyle = paragraphStyles

;

            newFont = getNewFont(paragraphStyle.appliedFont.name);

            if (newFont != null) {

                paragraphStyle.appliedFont = newFont;

            }

        }

        // Change in character styles

        for (var c = 1; c < characterStyles.length; c++) {

            characterStyle = characterStyles;

            newFont = getNewFont(characterStyles.appliedFont + "\t" + characterStyles.fontStyle);

            if (newFont != null) {

                characterStyles.appliedFont = newFont;

            }

        }

       

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

            var changed;

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

            app.findTextPreferences.appliedFont = fontList[0];

            app.changeTextPreferences.appliedFont = fontList[1];

            changed = doc.changeText();

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

        }

    }

    catch(err) { // if an error occurs, catch it and write the  document's name, error message and line# where it happened into the log

        gErrorLog.push(doc.name + " - " + err.message + ", line: " + err.line);

    }

}

function getNewFont(oldFontName) {

    var newFont = null;

   

    for (var p = 0; p < fontList.length; p++) {

        if (oldFontName == fontList

[0]) {

            newFont = app.fonts.itemByName(fontList

[1]);

            if (!newFont.isValid) {

                newFont = null;

            }

            break;

        }

    }

    return newFont;

}

And here's the test file I used for testing. I'm replacing "Minion Pro - Regular", "Myriad Pro - Regular".

I guess you may need clear override somewhere in the code -- clearOverrides() -- using one of three options:

  • OverrideType.ALL
  • OverrideType.CHARACTER_ONLY
  • OverrideType.PARAGRAPH_ONLY

Maybe only for empty lines. I can't say at the moment since I'm totally busy with finishing the current issue of our magazine and have no time to play with it.

— Kas

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
Contributor ,
Oct 09, 2017 Oct 09, 2017

Copy link to clipboard

Copied

Hi,

     Thank you for reply...

     I will check...

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
Contributor ,
Oct 09, 2017 Oct 09, 2017

Copy link to clipboard

Copied

Hi,

     I have tested that case. Its working when replacing fonts in paragraph and character style (ie., redefine process). 

    For normal Find and Replace its not working because tat case has based on style so when replacing font in style, its working but find and replace using findtext is not working.  That paragraph style has no overrides.

     Is there is any other method to replace that font using find and replace? Bcoz style change is redefined process.  Without redefine (Changes in Style) process, how to replace 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
Guru ,
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

Hi there,

I don't understand your English quite well.

Could you provide the following?

  1. A test file
  2. The code you run against the file
  3. A screenshot/brief description of the exact place where the problem occurs

I don't have free time to experiment with various font settings trying to recreate your problem.

— Kas

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
Contributor ,
Oct 12, 2017 Oct 12, 2017

Copy link to clipboard

Copied

Hi,

     Sorry... I don't know how to attach indesign file here...

   1. Attaching Screenshot.

     Screen shot 2017-10-12 at 17.24.07.png

   2.  Code:

var findFonts = ["Helvetica Neue LT Std\t45 Light"];

var replaceFonts = ["Helvetica Neue\tLight"];

var replacedCount = 0, foundCount = 0;

fontReplacement(findFonts, replaceFonts);

alert("Replaced!!!")

exit()

function fontReplacement(fFonts, rFonts)

{

   

    for(var fCnt = 0; fCnt < fFonts.length; fCnt++)

    {

        var fFont = fFonts[fCnt];

        var rFont = rFonts[fCnt];

       

        app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

        app.findChangeTextOptions.includeFootnotes = true;

        app.findChangeTextOptions.includeHiddenLayers = true;

        app.findChangeTextOptions.includeLockedLayersForFind = true;

        app.findChangeTextOptions.includeLockedStoriesForFind = true;

        app.findChangeTextOptions.includeMasterPages = true;

                     

        app.findTextPreferences.appliedFont = fFont;

        app.changeTextPreferences.appliedFont = rFont;

       

        found = app.activeDocument.findText();

        foundCount += found.length;

        changed = app.activeDocument.changeText();

        replacedCount += changed.length;               

       

        app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;    

    }

    alert("foundCount "+foundCount  + "\nreplacedCount " +replacedCount);

}

3. Refer Screen shot (Point #1).  In that, font applied to that text is replaced to the new font using the above code but font in the place "#" (without text) is not replaced. But using the Find Font (Manual), we can do that but it is not available in script.  So we used the option find and replace option.

     Using Find and replace (Text Preference) is not replacing all the occurrences of the font applied.  How to replace all fonts?

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
Guru ,
Oct 12, 2017 Oct 12, 2017

Copy link to clipboard

Copied

Sorry... I don't know how to attach indesign file here...

Send it me by e-mail: askoldich [at] yahoo [dot] com

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 ,
Oct 12, 2017 Oct 12, 2017

Copy link to clipboard

Copied

Hi Sudha,

That is because in that particular cell don't have any content. You can try this..

var myDoc = app.activeDocument;  

myRow = myDoc.stories.everyItem().tables.everyItem().rows.everyItem().getElements();    

for(var i=myRow.length-1; i>= 0; i--) 

{   

    for(var j=myRow.cells.length-1; j>= 0; j--) 

    {   

        if(myRow.cells.contents=="" ){myRow.cells.texts[0].appliedFont="Helvetica Neue\tLight";} 

    } 

Kasyan may provide a different approach I hope.

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
Contributor ,
Oct 12, 2017 Oct 12, 2017

Copy link to clipboard

Copied

Hi,

     Thank you for the reply... Its working for the table.... For the empty textframe (Same case "#") is also need to replace. Need to replace commonly in document.

     I want to know how to handle this by using find and replace.. Handle common in document based on fonts using find pallete..

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
Contributor ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

Hi,

     Can I send mail from adobe forum to send the test file.

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
Guru ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

I am not sure you can attach a file in PM.

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
Contributor ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

Hi,

     You have attached one test file for me.  How did you attach tat file... If you say i will attach file from forum.

    Here only the option for insert image, video and insert link...

    Can you guide me to attach file.

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
Guru ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

There are a number of on-line services: google disk, yandex disk, dropbox, wetransfer, etc. Usually you have to upload the file, share it, copy the link and paste it here on the forum.

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
New Here ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

@Kasyan Servetsky  i like your solution of changing character in a image file using photoshop scripting but i have to change  100 images fonts with different characters from a to z with different font styles , how can i do this?

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
Guru ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

aaish  wrote

@https://forums.adobe.com/people/Kasyan+Servetsky   i like your solution of changing character in a image file using photoshop scripting but i have to change  100 images fonts with different characters from a to z with different font styles , how can i do this?

It is an InDesign script and here's the InDesign scripting forum.
The Photoshop scripting forum is next door.

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
Explorer ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

LATEST

I am trying to use a version of this script but am having an issue...

it works on everything i need except if a character style is applied by the paragraph style

  for instance:

         bullets that are defined by a character syle within the paragraph style

        or a character style applied as a grep thru the paragraph style

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