Randomising sets of components within a glyph

I’m sadly no coding wizard and usually reach my results with blood sweat and tears, and some light scripting. For a current project I’m trying to look into the randomisation of components within a glyph.

Each glyph consists of only components, which are made out of two main sets. Within these sets are many more sub-components.

Is it possible to randomise these main sets of components with sub-components of their range? And if so, can this be done in one go, or should I split the two main sets in advance and then create a randomisation? And are there some naming conventions I should adhere to?

I’ll do some further delving myself, but if it’s possible, that would be nice to know. Thanks!

Yes, can be done. For example like this:

from random import choice
possibleNames = [g.name for g if g.name.startswith("_comp.")]
for g in Glyphs.font.glyphs:
    for l in g.layers:
       for c in l.components:
           c.componentName = choice(possibleNames)
1 Like

Cheers! Will look how tidy I’ll be change all of them.