Possible to duplicate/assign color to all layers in selected characters?

I’m slowly getting to grips with more and more scripting, but I can’t crack this one yet, but I believe this should be possible.

Once again I’m revamping a color font created out of components, and each color layer is filled with various parts. There is a lot of foreground-background interaction going on, so there are a lot of layers. Inside of the components, I’ve assigned colors as mini-illustrations, so the proper part is used when pasted inside a glyph. So this works, but now I have to apply these new color layers throughout all the glyphs :(.

So I wonder, is there a way to duplicate all (color palette) layers in a selected glyph/master? And even better, assign a specific color from the palette to all duplicates?

I’ll delve on myself in the meantime, but thanks in advance!

Not sure I fully understand what exactly you are trying to achieve. But you can access a layer’s attributes like this:

Layer.attributes["colorPalette"]=2

This makes the layer in question a CPAL layer for color index 2.

Hope this is a bit more clear in what I hope to do:

can you show that the glyph looks like and what those duplicate layer are?

I’ll send you the file!

I still don’t really understand what you are trying to do. But it looks impressive.

What do you start with and what is the result? Do you start with the full composition in the default layer and like to distribute each part into its own color layer?

The letters marked with green are done, I’ll make a screen recording to explain, it’s a bit of a construction…

Solved it in a different way, although now I’m running into a different issue:

The color layers don’t export properly in the variable version (normal color works fine). The glyphs are all made up of components with a stroke. For the variables to work I have to fully decompose before exporting. Changing the stroked shapes to outlines brings no change.

Of course this might have to do with the complexity, but I’ve had way more difficult things export fine. Oh and yes, I’ve checked the decompose filter, but that one only uses the master, not the layers.

I’ll send a batch of reference files if you want!

Could this be added to the documentation please? I was searching, trying and digging for a long time. Checked the method reporter and the forum to find this eventually here. It is a rather unintuitive API.

The info is there. Glyphs.app Python Scripting API Documentation — Glyphs.app Python Scripting API 3.0.4 documentation but it always can be improved.

Just added it to the docu page.

Thank you!
(I think I was searching the site for colorPalette yesterday and did not find it)