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

gradient as character style not working

Guru ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hey folks, i have a puzzler. 

 

So i have a gradient:

Screen Shot 2021-04-14 at 3.11.32 PM.png

 

when i want to apply that gradient to text, and make a character style, i find the gradient slider stops need to be moved to different locations for every instance of the same text in every different location:

 

this is the layout:

Screen Shot 2021-04-14 at 3.13.27 PM.png

and all 3 instances of this text need me to adjust the gradient manually to try to make it look consistent

Screen Shot 2021-04-14 at 3.06.23 PM.png

Screen Shot 2021-04-14 at 3.06.17 PM.png

Screen Shot 2021-04-14 at 3.06.23 PM.png

 

AND!!!

 

if i copy and paste it from one location to another. the gradient is gone:

Screen Shot 2021-04-14 at 3.16.29 PM.png

Screen Shot 2021-04-14 at 3.16.40 PM.png

 

Why?

TOPICS
How to

Views

470

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

Hi Jonathan, I think it is because gradient fills have a starting point and a length, which is relative to the page and not the word.

 

You can get the word’s position on the page so it would be possible to script the gradient’s position to match the word’s position and length. Something like this might work, where the name of your character style for the gradient is "GradientWord"

 

 

var st = app.activeDocument.stories
var cs = app.activeDocument.characterStyles.itemByName("GradientWord")
var 
...

Votes

Translate

Translate
Community Expert ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Hi Jonathan, I think it is because gradient fills have a starting point and a length, which is relative to the page and not the word.

 

You can get the word’s position on the page so it would be possible to script the gradient’s position to match the word’s position and length. Something like this might work, where the name of your character style for the gradient is "GradientWord"

 

 

var st = app.activeDocument.stories
var cs = app.activeDocument.characterStyles.itemByName("GradientWord")
var b,h,x,x2;
for(var i=0; i < st.length; i++){  
    var w = st[i].words; 
    for(var j=0; j < w.length; j++){  
        if (w[j].appliedCharacterStyle == cs) {
            b = w[j].baseline;
            h = w[j].horizontalOffset;
            x = w[j].parentTextFrames[0].geometricBounds[1];
            x2 = w[j].characters[w[j].length-1].horizontalOffset;
            w[j].gradientFillStart = [h-x, b];
            w[j].gradientFillLength = x2-h;
        } 
    }  
} 

 

Screen Shot 4.pngScreen Shot 5.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
Guru ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

That makes sense, would the script need to run in other machines? I go back with editors and they work from indesign.

 

thanks

jonathan

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

Copy link to clipboard

Copied

You’ll have to run the script anytime there is a text reflow.

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

Copy link to clipboard

Copied

LATEST

I believe the gradient is relative to the text frame, not the page.

 

If you select the text and press Command-Shift-O on a Mac (perhaps Control-Shift-O on PC) the selected text will be converted to outlines as an anchored object in the current text frame. It will no longer be text and can’t be edited. But as an object the gradent will apply normally.

Screenshot 2021-04-15 at 10.04.51 PM.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
Community Expert ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Also, if there are sequential words with the character style applied, this would be better.

 

var st = app.activeDocument.stories
var cs = app.activeDocument.characterStyles.itemByName("GradientWord")
var w,b,h,x,x2;
for(var i=0; i < st.length; i++){  
    //a range of words with the same style applied
    w = st[i].textStyleRanges; 
    for(var j=0; j < w.length; j++){  
        if (w[j].appliedCharacterStyle == cs) {
            //the gradient doesn’t work if the text range breaks
            w[j].noBreak = true;
            b = w[j].baseline;
            h = w[j].horizontalOffset;
            x = w[j].parentTextFrames[0].geometricBounds[1];
            x2 = w[j].characters[w[j].length-1].horizontalOffset;
            w[j].gradientFillStart = [h-x, b];
            w[j].gradientFillLength = x2-h;
        } 
    }  
} 

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

Copy link to clipboard

Copied

wow. thats cool. thank you

Question. In our team there are 2 designers and 4 editors, all running indesign 2021, do they all need to load and run this spcript everytime they make edits, text will reflows and the gradient is off again correct? 

 

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

Copy link to clipboard

Copied

Yes, reflowing text will change the gradient positions—moving the text frame won’t. If a phrase breaks the gradient wont work, so I added a no break. It probably would be better to use a backward loop—you may have to run the script twice if words were breaking.

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