Convert string #ff0000ff to color in python
I'm loading custom colors via CSV Import in NodeBox3 but have no
clue how to convert them to a real color.
I think I should use a custom Node for that (probably Python) but because there are no examples and documentation I have no clue how to do it.
Thanks for any advice.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by Frederik De Ble... on 12 Feb, 2014 08:49 AM
The Color class has a constructor that takes a hexadecimal value. Just use
Here is the Java class for Color.
2 Posted by jerimee.richir on 10 Sep, 2018 07:39 PM
But how does python have access to the Color class in Java?
Support Staff 3 Posted by john on 12 Sep, 2018 10:33 PM
Benny's original question was posted in January, 2013. Since then, after version 3.0.39 in March 2014, it is no longer necessary to create custom nodes to import colors from CSV files.
If your CSV has a color column with values formatted as hex values (e.g. #ECE8CE), you can just do a lookup on that column and pass the result directly into a color node or to the fill port of a colorize node. Other functions of that Java color class can be handled using existing NodeBox color nodes.
If your question was not so much about handling colors but about accessing Java code from within custom Python-based nodes, Frederik (NodeBox's creator) is much more knowledgeable than I am. My understanding is that some NodeBox nodes include references to original Java code accessed via Jython, "a version of Python 2.7 that runs on the JVM."
Please let us know if you are having a specific issue with either handling colors or accessing classes from within custom nodes. I can probably help with the former and Frederick or some other staff member should be able to help with the latter case.
Support Staff 4 Posted by Frederik De Ble... on 14 Sep, 2018 01:53 PM
John is absolutely right — the version of Python running in NodeBox is Jython, which has direct access to the Java VM. The Color class is not the one defined in Java, but NodeBox's own
nodebox.graphics.Color, which is loaded into the Jython script for you by default.