Change specific stroke colors

On the color layer, I have paths with red (#FF1950) and green strokes. I need to change all the red (only) strokes to blue. Here’s what I tried:

from GlyphsApp.plugins import NSColor
for layer in Glyphs.font.selectedLayers:
	for path in layer.paths:
		if path.attributes["strokeColor"] == "NSCalibratedRGBColorSpace 1 0.0980392 0.313725 1":
			path.attributes["strokeColor"] = NSColor.colorWithString_("#646EE1")

However the check doesn’t work and nothing happens after if line.
print(path.attributes) gives me the next output:

{
    strokeColor = "NSCalibratedRGBColorSpace 1 0.0980392 0.313725 1";
    strokeWidth = 30;
}

Should I check the stroke color somehow differently?

You can try to get the color components (single red, green and blue values) and compare those with a certain threshold.

1 Like

I found where I went wrong. The strokeColor attribute should be converted to string for equal comparison, so now it works:

from GlyphsApp.plugins import NSColor

red = 'NSCalibratedRGBColorSpace 1 0.0980392 0.313725 1'
blue = NSColor.colorWithString_('#646EE1')

for layer in Glyphs.font.selectedLayers:
	for path in layer.paths:
		if str(path.attributes['strokeColor']) == red:
			path.attributes['strokeColor'] = blue