Last active
August 29, 2015 14:10
-
-
Save Hoikohroh/6415bc095eef2004a077 to your computer and use it in GitHub Desktop.
Maxscript : exchange Hex color for RGB color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try destroyDialog exchangeHexForRgb catch() | |
Rollout exchangeHexForRgb "Hex" | |
( | |
colorpicker colorBox fieldwidth:25 height:25 color:(color 0 0 0) offset:[-12,0] across:2 | |
edittext hexCode "#" fieldwidth:68 height:20 offset:[-26,2] | |
on colorBox changed state do ( | |
local boxValue= #(bit.intAsHex colorBox.color.r, bit.intAsHex colorBox.color.g, bit.intAsHex colorBox.color.b) | |
try( | |
local hex = "" | |
for i in boxValue do | |
hex += (if i.count == 1 then "0" else "") + i | |
hexCode.text = hex | |
) | |
catch(print hex) | |
) | |
on hexCode changed text do( | |
local code = hexCode.text | |
case of | |
( | |
((substring code 1 1) == "#") : code = (filterString code "#")[1] | |
((substring code 1 2) == "0x"): code = (filterString code "0x")[1] | |
) | |
try( | |
local colRed = ("0x" + substring code 1 2) as integer | |
local colGreen = ("0x" + substring code 3 2) as integer | |
local colBlue = ("0x" + substring code 5 2) as integer | |
colorBox.color = color colRed colGreen colBlue | |
) | |
catch(print code) | |
) | |
) | |
createDialog exchangeHexForRgb 120 35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment