Hello! (Long time listener, first time caller)
I have some custom CSS colors stored as variables in my theme file. For example, "--neutral-10: #e6e6e6;"
I know that I can leverage this color in a Perspective component by setting the color to "--neutral-10" or (sometimes) "var(--neutral-10)." For example, I can set the text color of a label by setting the its "textStyle.color" to "--neutral-10"
But is there a way that I can access the HEX value of a CSS Variable in a Python script? Say I have a script to find a good contrasting-color to a hex value, and that script works if I pass it "#e6e6e6" directly, but is there a way I can pass it "--neutral-10" and have my script find the proper HEX value?
Thank you!
Notice that a CSS variable like --neutral-10
does not have a single hex color assigned to it, you would need to know which theme as well.
I'm not aware of a way to look it up in scripting.
Add transparency to built in theme color - Ignition - Inductive Automation Forum
1 Like
No, you can't.
Or, to be accurate, you could go and read the actual .css file with a script, parse it, and pull the variable you want out of it.
But that sounds like a terrible idea.
It seems like you're trying to find a way to transform colors dynamically.
If that's the case, I'd suggest reading up on the color()
function.
1 Like
CSS variables are basically automatically replaced strings when the CSS file is interpreted at runtime, and only 'exist' in a meaningful sense inside the frontend session. Your Python script(s) are only running on the backend, on the gateway. You'd need some kind of Javascript bridge to read values, and we don't provide one for you, nor are we likely to anytime soon.
2 Likes
Makes sense to me. Thanks all!