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

Possible to supply a hex value to solid's color property?

Participant ,
Aug 18, 2013 Aug 18, 2013

I know the AE Scripting Guide specifies that we have to supply an array of RGB values if we wish to change a solid's color property.  I'm just curious if it is possible to supply a hex value in lieu of an RGB array.  Does anybody have any experience with a work around?

Thanks!

TOPICS
Scripting
5.6K
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 1 Correct answer

Community Expert , Aug 18, 2013 Aug 18, 2013

The conversion is easy enough:

function hexToColor(theHex){

  var r = theHex >> 16;

  var g = (theHex & 0x00ff00) >> 8;

  var b = theHex & 0xff;

  return [r/255,g/255,b/255];

}

Dan

Translate
Community Expert ,
Aug 18, 2013 Aug 18, 2013

The conversion is easy enough:

function hexToColor(theHex){

  var r = theHex >> 16;

  var g = (theHex & 0x00ff00) >> 8;

  var b = theHex & 0xff;

  return [r/255,g/255,b/255];

}

Dan

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
Participant ,
Aug 18, 2013 Aug 18, 2013

Hey Dan thanks so much for your expertise and time!  This is really helpful.  I really appreciate it!

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
Participant ,
Aug 19, 2013 Aug 19, 2013

Dan,

Just wanted to add that I didn't realize your function assumed the hex color value would be passed in as `0xFFFFFF`.  My data was passed in as a string such as `FFFFFF`.  To fix, I just added one line:

function hexToColor(theHex){

  theHex = parseInt(theHex,16);

 

  var r = theHex >> 16;

  var g = (theHex & 0x00ff00) >> 8;

  var b = theHex & 0xff;

 

  return [r/255,g/255,b/255];

 

}

Thought this might help somebody who had the same data coming in question.  Thanks, again for the help.

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 ,
Aug 24, 2013 Aug 24, 2013

It did help somebody thanks!

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
Contributor ,
Jul 21, 2022 Jul 21, 2022

Very helpful thanks!

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
Valorous Hero ,
Jul 21, 2022 Jul 21, 2022
LATEST

AE now has a built-in, direct Expression method for hex to RGB conversion. More info here - 
https://ae-expressions.docsforadobe.dev/color-conversion.html

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
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