Gradient expression for FillPaint property

Hi,
is it possible to set a rectangle FillPaint property to a gradient color by using an expression based on some variable values? (I’m using Ignition 7.8.0)

Thank you in advance

Hello,

You wouldn’t be able to use a binding directly but you could do something like this through scripting and then work this into an expression binding using the runScript() expression function.

from com.inductiveautomation.ignition.client.util.gui.paints import RelativeLinearGradientPaint
from java.awt import Color
from java.awt.geom import Point2D

#RelativeLinearGradientPaint(java.awt.geom.Point2D start, java.awt.geom.Point2D end, float[] fractions, java.awt.Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod)
rlgp = RelativeLinearGradientPaint(Point2D.Double(0.0,0.5), Point2D.Double(1.0,0.5), [0.0, 0.4111675024032593, 1.0],[Color(255,0,0), Color(0,255,200), Color(0,0,255)], RelativeLinearGradientPaint.CycleMethod.NO_CYCLE)
event.source.parent.getComponent('Rectangle').fillPaint = rlgp

If you placed this script on a button it would change the gradient of a rectangle on screen to the specified colors and locations.

Let me know if this helps.

Best,

Hallo sngeru,
thank you very much, I will give it a try.

Regards

For Some reason it does not work to me.Could you please insert here the entire script included runScript() expression.