Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pasting HEX (color) values into Maya materials?

3 REPLIES 3
Reply
Message 1 of 4
Toquitaa
662 Views, 3 Replies

Pasting HEX (color) values into Maya materials?

Hey guys,

 

I'm quite new to Maya so it could be that I'm just not finding this.... but is it possible to paste a specific Hex color into a Maya material? Example: say I have an image open in GIMP/Photoshop and I got a specific color from a picture. I can copy the Hex value of this color and paste it everywhere, but Maya. In Maya I'm finding myself having to enter each RG value separately.

 

amarildosantinijr_0-1634219355958.png

 

3 REPLIES 3
Message 2 of 4
mspeer
in reply to: Toquitaa

Hi!

Sorry, this is not possible.

Message 3 of 4
zewt
in reply to: Toquitaa

I've wanted this many times.  Maya's color dialog really needs an update, or at least an API to let us revamp it ourselves (as far as I know there's no way to replace the color dialog in a plugin).

 

Message 4 of 4
hamsterHamster
in reply to: Toquitaa

A quick, a little bit messy way, but faster than converting and entering numbers by hand:

hamsterHamster_0-1634345029378.png

Takes 3 minutes to set up:

// HEX to RGB by nH v1.0 2021
// 1# In the Hypershade create colorConstant node (Maya>utilities) ;
// 2# In the AttrEditor add a custom attribute 'hex' of String type ;
// 3# expand ExtraAttributes section and enter some 6-digit hex code ;
// 4# RMB>Create New Expression.. next to the Color swatch, which will open ExpressionEditor ;
// 5# Cupy-Paste this text, click Create ;
// 6# Click Copy Tab button to keep it as a separate "panel" ;
// 7# Click Color swatch to source the RGB color to a custom color slot, then click the destination Color swatch and load the color from that slot ; 
// NOTE: Hex input less than 6 characters will result to default full RED color, non-hex characters will result in negative values ;

// tokenize hex dictionary
string $hexes = "0123456789ABCDEF" ;
string $hex_dict[] ;
for ( $i=0; $i<size($hexes); $i++ ){
	$hex_dict[$i] = `substring $hexes ($i+1) ($i+1)` ;
}

// get user input
string $input = `getAttr "colorConstant1.hex"` ;
    if (size($input)<6) $input = "FF0000" ; // default color
$input = `toupper $input` ;

// tokenize user input to decimal
string $hex[] ;
int $dec[] ;
for ( $i = 0; $i<6; $i++ ) {
    $j = `substring $input ($i+1) ($i+1)` ;
    $dec[$i] = `stringArrayFind $j 0 $hex_dict` ;
} 

// convert decimal to fractional
float $fract[];
for ( $i = 0; $i<3; $i++ ){
    $fract[$i] = ($dec[$i*2]*16.0 + $dec[$i*2+1])/255.0;
}

// output
colorConstant1.inColorR = $fract[0];
colorConstant1.inColorG = $fract[1];
colorConstant1.inColorB = $fract[2];

// if you want to run activate it from a MEL button, then use the following output string instead ;
// setAttr "colorConstant1.inColor" -type double3 $fract[0] $fract[1] $fract[2] ;

You can also rename the colorConstant node and save it as an asset... or even build a proper UI.. please post the code here and in Maya Ideas board.


,,,_°(O__O)°_,,,
Maya2019.1 @ Windows10 & GeForce GTX1080Ti

If the post was helpful, click the
 ACCEPT SOLUTION  button, so others might find it much more easily.

Tags (4)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report