Skip to main content
Lazlo_Hollyfeld
Inspiring
August 18, 2013
Resuelto

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

  • August 18, 2013
  • 1 respuesta
  • 6174 visualizaciones

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!

Este tema ha sido cerrado para respuestas.
Mejor respuesta de Dan Ebberts

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

1 respuesta

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertRespuesta
Community Expert
August 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

Lazlo_Hollyfeld
Inspiring
August 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.

Sebastien Lavoie
Known Participant
August 24, 2013

It did help somebody thanks!