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

Change colours using code

Explorer ,
Apr 11, 2023 Apr 11, 2023

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.

TOPICS
Expressions
508
Translate
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

LEGEND , Apr 11, 2023 Apr 11, 2023

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

 

Mylenium

Translate
Community Expert , Apr 11, 2023 Apr 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)
Translate
LEGEND ,
Apr 11, 2023 Apr 11, 2023

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

 

Mylenium

Translate
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 ,
Apr 11, 2023 Apr 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)
Translate
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 11, 2023 Apr 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)
Translate
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 ,
Apr 12, 2023 Apr 12, 2023
LATEST

Great, even better, thanks! I've been told off for "verbose code" before. 😆

Translate
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