# Color to string

**URL:** <https://forum.inductiveautomation.com/t/color-to-string/12662>\
**Category:** Ignition\
**Created:** [February 9, 2017, 1:45pm UTC](https://forum.inductiveautomation.com/t/color-to-string/12662 "2017-02-09T13:45:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jukka](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jukka](https://forum.inductiveautomation.com/u/Jukka)\
**Post date:** [February 9, 2017, 1:45pm UTC](https://forum.inductiveautomation.com/t/color-to-string/12662/1 "2017-02-09T13:45:20Z")

</div>

Is there any way to read the color from the Power table and convert it to string, where R,G and B values can be read?

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/50f319b583d2f51d8939fe9dd4181f4ddc3e5744.JPG)

I need to store these values to MySql database as a string.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 9, 2017, 2:48pm UTC](https://forum.inductiveautomation.com/t/color-to-string/12662/2 "2017-02-09T14:48:09Z")

</div>

Click on the little color wheel.

---

<div class="post-metadata">

**Author:** ![Jukka](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jukka](https://forum.inductiveautomation.com/u/Jukka)\
**Post date:** [February 10, 2017, 7:58am UTC](https://forum.inductiveautomation.com/t/color-to-string/12662/3 "2017-02-10T07:58:45Z")

</div>

I forgot to mention that I need to handle the Color datatype in scripting.

Now I'm reading all the values from COLOR column using the following script

* * *

## table = event.source.data data1 = system.dataset.toPyDataSet(table) for row in data1: c = row["COLOR"]

c is then stored to database. In the database the field looks like this

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e393c96c40e8baf260c8a2b55cff2af50de2829b.JPG)

Is there any way to convert the value c to understandable string?

---

<div class="post-metadata">

**Author:** ![Amarth](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarth/32/3313_2.png) [@Amarth](https://forum.inductiveautomation.com/u/Amarth)\
**Post date:** [February 10, 2017, 8:29am UTC](https://forum.inductiveautomation.com/t/color-to-string/12662/4 "2017-02-10T08:29:00Z")

</div>

It looks like you are actually storing the Java color object in the database.  
If you want to store it as a readable string, you can give a try to the str() function. It should give you a string like this : “java.awt.Color[r=xxx,g=xxx,b=xxx]”  
Storing str© instead of c should do the trick.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 11, 2017, 12:36am UTC](https://forum.inductiveautomation.com/t/color-to-string/12662/5 "2017-02-11T00:36:11Z")

</div>

Alternately, if you want a little bit nicer format (or perhaps separate columns) the Color object also has various get\* methods that are useful:

```auto
color = event.source.parent.getComponent('Button 1').buttonBG
print color.getRed()
print color.getGreen()
print color.getBlue()
print color.getAlpha()

```
