Yes I use IDs and also groups. For example put all gas lines in one group one oil lines in other group then loop thought and assign them correct colour base on their ids
Thanks! Im trying this and its pretty good as long as you keep the nesting really flat. But I have a question: what if you want to use style classes? The svg import doesnt have style:classes attributes. There isnt a function i know of to add them everywhere with script inside ignition directly if you're using an iterator, though apparently if you do a getsibling reference it does... How do you add the atttributes and get rid of fills that conflict with them? Do you process the svg externally first before importing?
The SVG elements are just json/(dicts/lists), so you can add and remove keys at your own discretion, including any fill.paint and style.classes keys
What is the value
here in your transform? I'm assuming a stroke dictionary? The dictionary didn't work.
The colour as a string
Gotcha, it does not seem to like Hex color strings, even though the SVG XML specifies the color like this: stroke:#eb1818
Hex string should work too, did you notice the ''
?
stroke='"+value+"'
Si, Senor.
data:image/svg+xml, <svg xmlns='http://www.w3.org/2000/svg' viewBox='20 0 96 96'><rect width='10%' height='100%' stroke='red'/></svg>
This works.
stroke='#ff0000'
this does not:
I don't know why this does not work, since in the SVG XML the
#
exists.
Neither does this: stroke='"#ff0000"'
.
Nor this: stroke='"+#ff0000+"'
. This should not work because the Hex value is not a variable.
Nor this: stroke='ff0000'
. The rendered color is black
, same result I get when using this: stroke='"+value+"'
, probably because the Designer does not have a real color value to use (render?) and black
is the fallback? The color should be red
.
Not sure what I'm missing Victor.
EDIT: I changed the size btw, just playing around with it.
Oke i found the issue, its a string to url parsing issue...
replace #
with %23
(its the url code for #)
`
Yeah, never would have guessed that, lol. Thanks!
I would do the encoding in the script transform:
from java.net import URLEncoder
return "data:image/svg+xml, <svg xmlns='http://www.w3.org/2000/svg' viewBox='20 0 96 96'><rect width='10%' height='100%' stroke='" + URLEncoder.encode(value) + "'/></svg>
Then you can set the expression to #ff0000
which is probably more obviously a color to others you may look at this in the future.
For reference this:
from java.net import URLEncoder
value = '#ff0000'
print URLEncoder.encode(value)
Outputs:
>>>
%23ff0000
>>>
Hm i actaully think "#" might be one of the few unique url encoded cases, and not everything has to (or even is allowed) to be encoded. a replace ('#') might be safer (untill you come across other examples).
but i havent rly looked into it much... but its clear that spaces do work, while it might break those after encoding them too %20 (no idea if it does)