I’m trying this format but it’s not working
text.setRangeFills(start, end, object.fills)
It must be an array of objects.
Yes it is, but it still doesn’t work. Here’s object.fills:
[
{
"type": "SOLID",
"visible": true,
"opacity": 1,
"blendMode": "NORMAL",
"color": {
"r": 0.9416666626930237,
"g": 0,
"b": 3.367662486652989e-7
}
}
]
What error do you see in the console?
RGB values are specified from 0 to 1.
I don’t see any error.
I am trying to get and set fills for a text node.
The reference text is “hello”, where “he” is white and “llo” is red.
When I apply the fills to the output, it is all white and not according to the reference text.
it is between 0 and 1
How many times do you call the setRangeFills
method?
20 times in the above case (string.length * 4)
Sorry, but you are doing something wrong. You only need to call this method 2 times. The first time to set the fill to white, the second time to set it to red.
text.setRangeFills(0, 2, [whiteFill]);
text.setRangeFills(3, 5, [redFill]);
Sorry for the confusion.
I am calling it 2 times per Text Node. I have 2 text nodes for each letter in the string.
So, 2 x 2 x 5 = 20
At the moment, I can only suggest that you revise your code that was left behind the scenes. Or share enough code so that anyone can reproduce what you’re experiencing.
I rewrote my code snippet separately, and it worked fine.
let refText = figma.currentPage.findOne(n => n.name === "Testing...") as TextNode
let styles = refText.getStyledTextSegments(['fills'])
let subject = figma.currentPage.selection[0] as TextNode
for (let style = 0; style < styles.length; style++) {
const object = styles[style]
subject.setRangeFills(object.start, object.end, object.fills)
}
figma.closePlugin()
Now I will compare and see what mistake I am making. Thanks for the help, @tank666