Copy glyph from default layer to another
ThunderNixon last edited by gferreira
I'm trying to copy a glyph from its default layer to a background layer. I'm doing it in script, so I can eventually do it for all glyphs in a UFO.
I think this copying is relatively simple with a
pointPen, but I must be missing a critical part.
Here's my code for doing it to the current glyph, which already has a "bg" layer (unless I'm misunderstanding the UFO structure, which is a possibility). It doesn't yet work.
glyph = CurrentGlyph() glyphDefaultLayerName = glyph.layers.layer.name glyphDefaultLayer = glyph.getLayer(glyphLayerName) pen = glyphDefaultLayer.getPointPen() # just to make sure layer is there and cleared glyphLayer = glyph.newLayer("bg") ## doesn't work ... not sure why glyph.getLayer("bg").drawPoints(pen) ## also doesn't work # f.getLayer("bg")[glyph.name].drawPoints(pen)
Any insight is very appreciated!
ThunderNixon last edited by
Was told the solution by a helpful person. Turns out,
Also, I didn't need to get the name of the layer and use that to get the layer... obviously. 😄
Here's the code:
glyph = CurrentGlyph() glyph.layers.copyToLayer("bg", clear=True) # apparently, better than matching `width` glyph.getLayer("bg").leftMargin = glyph.layers.leftMargin glyph.getLayer("bg").rightMargin = glyph.layers.rightMargin
FosterType last edited by
This post is deleted!
font = CurrentFont() # use font.templateSelectedGlyphNames is you need the template glyphs for glyphName in font.selectedGlyphNames: glyph = font[glyphName] ... # the above script