Skip to main content
Inspiring
April 11, 2023
Answered

Change colours using code

  • April 11, 2023
  • 1 reply
  • 797 views

Hello, I am trying to figure out how to change a fill colour with code. For example, if I have a solid with a colour overlay of red how can I change this to another hex value? Many thanks.

This topic has been closed for replies.
Correct answer Dan Ebberts

You just need to make sure you get the value of the sourceText:

var hexColor = thisComp.layer("TextLayer").text.sourceText.value;
hexToRgb(hexColor)

1 reply

Mylenium
Legend
April 11, 2023

hexToRgb(your color code here) into whatever property or effects control you want. 

 

Mylenium

PsychromeAuthor
Inspiring
April 11, 2023

Great, thanks. I was also trying to read the value from a text layer so I needed to convert it to a string otherwise it gave me an error...

var hexColorSource = thisComp.layer("TextLayer").text.sourceText;
var hexColor = hexColorSource.value.toString();
hexToRgb(hexColor)
Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 11, 2023

You just need to make sure you get the value of the sourceText:

var hexColor = thisComp.layer("TextLayer").text.sourceText.value;
hexToRgb(hexColor)