Convert string #ff0000ff to color in python

Benny Schudel's Avatar

Benny Schudel

22 Jan, 2013 09:19 AM

Hello

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.

Benny

  1. Support Staff 1 Posted by Frederik De Ble... on 12 Feb, 2014 08:49 AM

    Frederik De Bleser's Avatar

    The Color class has a constructor that takes a hexadecimal value. Just use

    c = Color("#11223344")
    

    Here is the Java class for Color.

  2. 2 Posted by jerimee.richir on 10 Sep, 2018 07:39 PM

    jerimee.richir's Avatar

    But how does python have access to the Color class in Java?

  3. Support Staff 3 Posted by john on 12 Sep, 2018 10:33 PM

    john's Avatar

    Hi Jerimee,

    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.

    Thanks,

    John

  4. Support Staff 4 Posted by Frederik De Ble... on 14 Sep, 2018 01:53 PM

    Frederik De Bleser's Avatar

    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.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

18 Nov, 2024 11:24 PM
18 Nov, 2024 09:01 PM
07 Nov, 2024 10:53 AM
02 Nov, 2024 11:22 AM
01 Nov, 2024 12:41 AM

 

01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM
30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM
26 Sep, 2024 06:41 AM