Cannot add custom colors to Power Chart pens generated by script

Hi all,

I want to add pens to a Power Chart via a script, I needed to recreate the tag browser because I mapped all the tags with a script as well and the naming scheme was not 'operator friendly'.

I got all the pieces right, but I ran into an issue. I cannot add custom colors to the created pens. I created a random RGB hex function that inserted the values into the pen's display -> styles -> {mode} -> color, but it does not recognize it as a color class object, just a string, and colors the pen in grey. I tried rgb(int, int, int) and rgba(int, int, int, 1), still no luck. If I don't map styles at all in my script, all the created pens default to the same light teal color.

Is there any function / workaround that can allow me to create a color class object in Jython scripting? I have seen something about system.gui.color for Vision, but the project is in Perspective. I'm quite stuck here.


Perspective color values need to be a recognized CSS color format. Hex works, as does rgb and certain color names.
The following values as strings should be valid:

  1. #FF0000 (or #ff0000)
  2. rgb(255, 0, 0)
  3. red

So I would have expected your rgb approach to work (although the alpha inclusion has spotty support between browsers).

Avoid system.gui package functions as - just as you said - those are scoped for Vision. Also, avoid any expression Color types as those are Color Java objects - not CSS-recognized strings.

Could you print out the EXACT values your script is supplying? Please wrap them as strings before they are output from your script.

Thank you for helping!

This is a snippet of the script that I am using:

def random_rgb(self):
	import random
	_red = random.randint(0, 255)
	_green = random.randint(0, 255)
	_blue = random.randint(0, 255)
	rgb_hex = "#{:02x}{:02x}{:02x}".format(_red, _green,_blue)
	return rgb_hex.upper()

It returns a string, something like #353A4D , or #F557A1. I have tried basically function with rgb() and rgba(), with or without the .upper() method for hex values, and with or without calling str(...) before returning the value.

I attached a screenshot with a value inserted by the script for one pen creation. It adds them correctly, at least I think and hope so, but it does not recognize it as a color, no color picker next to the inserted hex, like the one you get when manually creating a pen by pressing the + icon. The Power Chart defaults to the teal color even if the color field is populated.

Hope this helps, and thanks again!

1 Like

What version of Perspective are you using? I don't see the same behavior when I attempt this with the PowerChart, and I actually see a different property structure: pens[x].display.styles.normal.stroke.color (note the "s" in `styles). I'm using the nightly code from last week, so perhaps this is something we resolved at some point in time.

Screenshot 2023-10-01 at 5.35.39 PM

is there any chance you're creating the entire style object within your script? This might be the result of a typo in that styles property within your script.

Well, this is embarrassing... This was the issue. Thank you for helping and sorry for wasting your time.

Have a nice day!

1 Like