Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


[HELP] Replacing character color to match the one before it.

Community Beginner ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

Hi 

 

I have a documant with 6 charcter styles: Black, Green, Red, and 3 other with the same colors plus a shadow (underline).

Currently all the shadowed character are in black, what I want to do is to change the color to match the character color before it, so if it's a Red then it should be Red with shadow instead of Black with shadow, 

Is there an easy way to that? or I must do it manually?

 

1.png

TOPICS
How to, Scripting, Type

Views

90

Likes

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 2 Correct answers

Adobe Community Professional , Nov 14, 2021 Nov 14, 2021
Please ignore my earlier post. I misinterpreted your issue. My solution will change the style of text before another style. This will work to change the style of text after another style. Here I was using cahracter colour, but any formatting can be used for your search term or your replace formatting. Find:  Replace: $1@ This will just add an @ to the beginning of hte found text. Find: @  Replace:  @ This will move the @ to the end of the text you want to format, so there isnt a space between t...

Likes

Translate

Translate
Community Beginner , Nov 15, 2021 Nov 15, 2021
Thanks, this one worked after a few adjustments: 1- Add the @ character for the desired color, note: If I leave find what empty it won't work, it replace the found text with ($1@) text.2-3- Change the style: Thanks again for your help. 

Likes

Translate

Translate
Adobe Community Professional ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

Are you applying this shadow using a character style?

If so, does that character style have a colour defined in it? If it does, remove the colour from the character style, so that all the char style does is apply underline and not a colour.

Likes

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
Adobe Community Professional ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

You have to select the color of the character and its underline, you can use for the shaddow separately. It is not possible to define character color, and then text color for the underlin if a tint value is selected automatically. Here, the developers have potential improvement of this functionality.

Likes

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
Adobe Community Professional ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

You could use GREP in Find/Change to insert a dummy character between the text you want to change and the text you want to find. Here I inserted a @ at the beginning of the green text by searching for anything that is green (note the Find Format section).

Search for (.+) Replace with @$1

Screenshot 2021-11-14 at 8.55.45 AM.png

Next I searched for the @ sign (it doesn't matter what symbol I use, so long as it doesn't appear anywhere else in the story). What I'm actually searching for is any number (/d) or (|) uppercase letter (/u) that repeats (+) folowed by a space and a @. I replaced with the found text ($1) followed by a space, since I don't need the @ anymore.

Search for ( [\d|\u]+) @ Replace with $1 

Note the space after $1 because I want to keep that.

Screenshot 2021-11-14 at 9.08.11 AM.png

You'll have to repeat this for each format you want to apply it to. You can’t use GREP Styles because that s only content based, GREP Styles can only format text based on the text, not based on the formatting of text. The replacement will probably go easier if you make a character style for hte formatting you want to apply.

Likes

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
Adobe Community Professional ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

For some reason I cannot edit my posts. The forum has some serious issues on my version of Safari.

 

So I wanted to suggest a change. For the second search, do this instead. The difference is the space between the numbers is not part of the found text, so if you are applying shading the space will not be affected.

Search for ([\d|\u]+)(?= @) Replace with $1

Note no trailing space after $1 in this version. Only the 3333 is affected.


Screenshot 2021-11-14 at 9.16.02 AM.png

Likes

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
Adobe Community Professional ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

Please ignore my earlier post. I misinterpreted your issue. My solution will change the style of text before another style. This will work to change the style of text after another style. Here I was using cahracter colour, but any formatting can be used for your search term or your replace formatting.

Find: 
Replace: $1@

This will just add an @ to the beginning of hte found text.

Screenshot 2021-11-14 at 12.26.31 PM.png

Find: 

Replace:  @

This will move the @ to the end of the text you want to format, so there isnt a space between the text and the @ symbol. Note no formatting in either section.

 

Screenshot 2021-11-14 at 12.27.15 PM.png

Find: @([\d|\u]+)

Replace: $1

This will fix the formatting and remove the @ symbol.

Screenshot 2021-11-14 at 12.28.41 PM.png

Likes

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 ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

LATEST

Thanks, this one worked after a few adjustments:

 

1- Add the @ character for the desired color, note: If I leave find what empty it won't work, it replace the found text with ($1@) text.

1111.png

2-

22.png

3- Change the style:

333.png

 

Thanks again for your help. 👍👍

Likes

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
Enthusiast ,
Nov 14, 2021 Nov 14, 2021

Copy link to clipboard

Copied

Hi @AK09M, if for some reason the great suggestions already posted here don't work in your case, and since you tagged scripting, here is a script that should do what you are asking for. It finds any text in the character style, then checks the preceding character's color and sets the found text to that color. Let me know if you end up using it and if it works for you. If you want to modify the script, change the "overrideCharacterStyleColor" function—the rest is just generic UI.

- Mark

 

 

/*

    Override CharacterStyle Color.js

    by m1b, here: https://community.adobe.com/t5/indesign-discussions/help-replacing-character-color-to-match-the-one-before-it/m-p/12522689

    Finds any text with character style applied and match its color to that of the preceding character.

*/

function main() {

    // this is a call to make the UI
    // the callback calls the actual overriding function
    dialogWithMenu({
        document: app.activeDocument,
        menuItems: app.activeDocument.characterStyles.everyItem().name.slice(1),
        windowTitle: 'Override Character Style Color',
        intro: 'Find any text with style applied and match its color to that of the preceding character.',
        menuLabel: 'Style: ',
        buttonTitle: 'Override',
        selectedItemIndex: 0,
        callback: function (p) {
            if (p.menuName != undefined)
                overrideCharacterStyleColor(p.document, p.menuName)
        }
    });


    function overrideCharacterStyleColor(doc, styleName) {
        // will find text with characterStyle applied and
        // match its color to that of the preceding character

        if (!doc.characterStyles.itemByName(styleName).isValid) {
            alert('No character style named "' + styleName + '" found.')
            return;
        };

        app.findGrepPreferences = NothingEnum.NOTHING;
        app.changeGrepPreferences = NothingEnum.NOTHING;
        app.findGrepPreferences.appliedCharacterStyle = styleName;

        var found = doc.findGrep();
        for (var i = found.length - 1; i >= 0; i--) {
            if (found[i].index - 1 > 0) {
                var previousChar = found[i].parentStory.characters[found[i].index - 1];
                found[i].fillColor = previousChar.fillColor;
                found[i].fillTint = previousChar.fillTint;
            }
        }

    }

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Override Character Style Color');


function dialogWithMenu(p) {
    var dialog = makeUI(p);
    dialog.center();
    var result = dialog.show();
    if (result == 1) {
        // pass the text to the callback function
        if (p.callback != undefined)
            p.callback({
                document: p.document,
                menuIndex: p.menuIndex,
                menuName: p.menuName
            });
    }
    dialog = null;

    function makeUI(p) {
        var windowTitle = p.windowTitle || '',
            menuItems = p.menuItems || [],
            menuLabel = p.menuLabel || 'Choose:',
            menuChangeFunction = p.menuChangeFunction || function (p) { },
            w = new Window("dialog", windowTitle);

        if (p.intro != undefined)
            w.add('statictext', undefined, p.intro, { alignment: 'left', multiline: true });

        var row = w.add("Group {orientation:'row', alignment:['fill','top']}"),
            mainMenu = row.add("Dropdownlist {alignment:['left','center']}");

        if (p.buttonTitle != undefined) {
            var okButton = w.add('button', undefined, p.buttonTitle, { name: 'ok' });
            okButton.onClick = function () { w.close(1) };
        }

        mainMenu.preferredSize.width = 250;
        mainMenu.title = menuLabel;
        for (var i = 0; i < menuItems.length; i++) {
            mainMenu.add('item', menuItems[i]);
        }
        mainMenu.onChange = menuOnChange;
        if (p.selectedItemIndex != undefined) mainMenu.selection = p.selectedItemIndex;
        return w;

        function menuOnChange() {
            p.menuIndex = mainMenu.selection ? mainMenu.selection.index : 0;
            p.menuName = String(mainMenu.selection);
        }
    }
}

 

 

Likes

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