<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Copy glyph from default layer to another]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">I think this copying is relatively simple with a <code>pointPen</code>, but I must be missing a critical part.</p>
<p dir="auto">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.</p>
<pre><code>glyph = CurrentGlyph()

glyphDefaultLayerName = glyph.layers[0].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)

</code></pre>
<p dir="auto">Any insight is very appreciated!</p>
]]></description><link>https://forum.robofont.com/topic/524/copy-glyph-from-default-layer-to-another</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 12:24:52 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/524.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Oct 2018 01:25:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Copy glyph from default layer to another on Mon, 22 Oct 2018 15:57:59 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">I think this copying is relatively simple with a <code>pointPen</code>, but I must be missing a critical part.</p>
<p dir="auto">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.</p>
<pre><code>glyph = CurrentGlyph()

glyphDefaultLayerName = glyph.layers[0].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)

</code></pre>
<p dir="auto">Any insight is very appreciated!</p>
]]></description><link>https://forum.robofont.com/post/1781</link><guid isPermaLink="true">https://forum.robofont.com/post/1781</guid><dc:creator><![CDATA[StephenNixon]]></dc:creator><pubDate>Mon, 22 Oct 2018 15:57:59 GMT</pubDate></item><item><title><![CDATA[Reply to Copy glyph from default layer to another on Mon, 22 Oct 2018 01:46:22 GMT]]></title><description><![CDATA[<p dir="auto">Was told the solution by a helpful person. Turns out, <code>copyToLayer</code> works great!</p>
<p dir="auto">Also, I didn't need to get the name of the layer and use that to get the layer... obviously. 😄</p>
<p dir="auto">Here's the code:</p>
<pre><code>glyph = CurrentGlyph()

glyph.layers[0].copyToLayer("bg", clear=True)

# apparently, better than matching `width`
glyph.getLayer("bg").leftMargin = glyph.layers[0].leftMargin
glyph.getLayer("bg").rightMargin = glyph.layers[0].rightMargin
</code></pre>
]]></description><link>https://forum.robofont.com/post/1782</link><guid isPermaLink="true">https://forum.robofont.com/post/1782</guid><dc:creator><![CDATA[StephenNixon]]></dc:creator><pubDate>Mon, 22 Oct 2018 01:46:22 GMT</pubDate></item><item><title><![CDATA[Reply to Copy glyph from default layer to another on Mon, 22 Oct 2018 04:22:57 GMT]]></title><description><![CDATA[<p dir="auto">Basic question, how might one rewrite this for selected glyphs only?</p>
]]></description><link>https://forum.robofont.com/post/1783</link><guid isPermaLink="true">https://forum.robofont.com/post/1783</guid><dc:creator><![CDATA[FosterType]]></dc:creator><pubDate>Mon, 22 Oct 2018 04:22:57 GMT</pubDate></item><item><title><![CDATA[Reply to Copy glyph from default layer to another on Mon, 28 Jan 2019 10:12:17 GMT]]></title><description><![CDATA[<pre><code class="language-python">font = CurrentFont()

# use font.templateSelectedGlyphNames is you need the template glyphs
for glyphName in font.selectedGlyphNames:
    glyph = font[glyphName]
    # the above script
</code></pre>
<p dir="auto">good luck!!</p>
]]></description><link>https://forum.robofont.com/post/1789</link><guid isPermaLink="true">https://forum.robofont.com/post/1789</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Mon, 28 Jan 2019 10:12:17 GMT</pubDate></item><item><title><![CDATA[Reply to Copy glyph from default layer to another on Sun, 28 Apr 2019 23:56:26 GMT]]></title><description><![CDATA[<p dir="auto">As a later follow-up, I've found that <code>copyLayerToLayer</code> is actually more what I was looking for, as it just copies over everything without issue: contours, anchors, width, guidelines. <code>copyToLayer</code> is nice in that it gives more control, if you want it.</p>
<pre><code>from mojo.UI import AskString

f = CurrentFont()

newLayer = AskString('Layer to copy all existing glyphs to, e.g. "overlap"')

for glyph in f:
    glyph.layers[0].copyLayerToLayer("foreground", newLayer)
</code></pre>
]]></description><link>https://forum.robofont.com/post/2286</link><guid isPermaLink="true">https://forum.robofont.com/post/2286</guid><dc:creator><![CDATA[StephenNixon]]></dc:creator><pubDate>Sun, 28 Apr 2019 23:56:26 GMT</pubDate></item><item><title><![CDATA[Reply to Copy glyph from default layer to another on Mon, 08 Feb 2021 20:48:51 GMT]]></title><description><![CDATA[<p dir="auto">I’ve adjusted this to go through the currently-selection glyphs only, and to clear the non-foreground layer before copying to it.</p>
<pre><code>from mojo.UI import AskString

f = CurrentFont()

newLayer = AskString('Layer to copy all existing glyphs to, e.g. "overlap"')

for glyphName in f.selection:
    
    glyph = f[glyphName]
    
    glyph.getLayer(newLayer).clear() # if you wish to clear the non-foreground layer
    
    glyph.layers[0].copyLayerToLayer("foreground", newLayer)
    
    glyph.getLayer(newLayer).leftMargin = glyph.layers[0].leftMargin
    glyph.getLayer(newLayer).rightMargin = glyph.layers[0].rightMargin
</code></pre>
]]></description><link>https://forum.robofont.com/post/3579</link><guid isPermaLink="true">https://forum.robofont.com/post/3579</guid><dc:creator><![CDATA[ArrowType]]></dc:creator><pubDate>Mon, 08 Feb 2021 20:48:51 GMT</pubDate></item></channel></rss>