Exporting layers?

Hello,

is there a way to export all the layers in for example form of vector file or image? I wish to create an animation with the ‘process’ of shaping letters, and I have quite a lot of layers… and it would take forever to do it manually.

thanks

That could be done with a small drawbot script. https://github.com/schriftgestalt/DrawBotGlyphsPlugin

Thanks,

Could someone help or suggest anything with the script as my coding skills are equal zero? Would be great

That would be a good time to sit down one evening and learn the basics. Easier than you might think:
https://www.glyphsapp.com/tutorials/articles/tag:python

So, what should I do is to access a path of letters on different layers and then tell the drawbot to draw it according to the path and save?

Yes. You can ask the layers for a bezierPath. That can be used to draw in drawbot.

Try this as a starter:

from GlyphsApp import *

myFont = Glyphs.font
selectedLayers = myFont.selectedLayers

fill(0.5, 1.0/len(selectedLayers)) # set color

for thisLayer in selectedLayers:
    # draws paths:
    drawPath(thisLayer.bezierPath)
    
    # draws components:
    for thisComponent in thisLayer.components:
        drawPath(thisComponent.bezierPath)

When you call the bezierPath object of a layer, components are ignored. That is why there is an extra loop just for components.

Hey guys, I am trying to achieve the same goal, also with the same “coding skills are equal zero” as KrzyweTo mentioned! ; )

I tried the script and got the attached results, an “A” Glyph cropped. If I select more than I Glyph I get "A,B,C) into the same file/artboard also cropped.

My question is:

How can I export all selected Glyphs into separate files, without being cropped?

Super appreciate if anyone can help!

Best
Alex

Update…

I was able to generate multiple artboards, but when selecting multiple Glyphs they went to the same dartboard, as you can see on the GIF bellow:

from GlyphsApp import *

myFont = Glyphs.font
selectedLayers = myFont.selectedLayers

loop over a range of 100

for i in range(100):
# for each loop create a new path
newPage(500, 500)

fill(0.5, 1.0/len(selectedLayers)) # set color

for thisLayer in selectedLayers:
# draws paths:
drawPath(thisLayer.bezierPath)

# draws components:
for thisComponent in thisLayer.components:
    drawPath(thisComponent.bezierPath)

You need to put the page(500, 500) inside the loop over the selected layers.
something like this:

from GlyphsApp import *

myFont = Glyphs.font
selectedLayers = myFont.selectedLayers

for thisLayer in selectedLayers:
    newPage(500, 500)
    drawPath(thisLayer.completeBezierPath)

you need to set the correct scale and position. So the script would look like this:

from GlyphsApp import *

Height = 500
extraSpace = 1.2

myFont = Glyphs.font
selectedLayers = myFont.selectedLayers

master = myFont.masters[myFont.masterIndex]

Scale = Height / (myFont.upm * extraSpace)

offsetY = -master.descender

for thisLayer in selectedLayers:
    newPage(Height, Height)
    save()
    scale(Scale)
    offsetX = ((Height / Scale) - thisLayer.width) / 2
    translate(offsetX,offsetY)
    drawPath(thisLayer.completeBezierPath)
    restore()

Worked PERFECT Georg, thanks so much man!!! : )

The only issue is saving…
I tried what you suggested on the other thread but got an error. Do you know what I am doing wrong?

from GlyphsApp import *

Height = 500
extraSpace = 1.2

myFont = Glyphs.font
selectedLayers = myFont.selectedLayers

master = myFont.masters[myFont.masterIndex]

Scale = Height / (myFont.upm * extraSpace)

offsetY = -master.descender

for thisLayer in selectedLayers:
    newPage(Height, Height)
    save()
    scale(Scale)
    offsetX = ((Height / Scale) - thisLayer.width) / 2
    translate(offsetX,offsetY)
    drawPath(thisLayer.completeBezierPath)
    restore()
    
 save("desktop/test1.png") 

ERROR:
Traceback (most recent call last):
File “”, line 24
save(“desktop/test1.png”)
^
IndentationError: unindent does not match any outer indentation level

Also is it possible to have a script that automatically saves with a name as:

fontfamily/fontvariation/glyph

example:
helveticaneue/extrathin/a
helveticaneue/extrathin/b

This will save a ton of time as I have thousands of fonts to export images

Again, thanks a lot!!!

There is an extra space before the save. It gives an IndentationError, that means that the space before the command is wrong.

And you might need to put the save() call inside the loop.

thanks Georg, worked!

I had to export as PDF, as it’s the only option for multi page export. But it’s ok since it can be easily converter to PNG afterwards.

@alsg did you manage to access all the layers in one glyph? Your code only exports the selected layer in each glyph.
I need to export all the layers as image to make a time line with the evolution of each glyph drawing

You can access all layers in a glyph by its layers property. Have a look at docu.glyphsapp.com

Thanks Georg!
Happy new year!
:slight_smile:

I’ve managed to get the layers in one glyph.
Here’s the code:

from GlyphsApp import *

Height = 1000
extraSpace = 1.2

layers = Glyphs.font.glyphs[“a”].layers

print len(layers) , (“layers in this glyph”)

master = Glyphs.font.masters[Glyphs.font.masterIndex]

Scale = Height / (Glyphs.font.upm * extraSpace)

offsetY = -master.descender + 50

for i in range(len(layers)):
print(layers[i])
newPage(Height, Height)
save()
scale(Scale)
offsetX = ((Height / Scale) - layers[i].width) /2
translate(offsetX, offsetY)
drawPath(layers[i].completeBezierPath)
restore()
saveImage(“~/Documents/proto_offline/Karte/drawbot/export/test.png”, 300)

However, I’m trying to loop through all the glyphs and all the layers in each glyph.
Here’s what I’ve written but it doesn’t work.
Can someone point me in the right direction?

from GlyphsApp import *

Height = 1000
extraSpace = 1.2

glifo = Glyphs.font.glyphs
layers = glifo.layers

print = len(glifo), (“glyphs in this font”)
print len(layers) , (“layers in this glyph”)

master = Glyphs.font.masters[Glyphs.font.masterIndex]

Scale = Height / (Glyphs.font.upm * extraSpace)

offsetY = -master.descender + 50

for i in range(len(layers)):
print(layers[i])
newPage(Height, Height)
save()
scale(Scale)
offsetX = ((Height / Scale) - layers[i].width) /2
translate(offsetX, offsetY)
drawPath(layers[i].completeBezierPath)
restore()
saveImage(“~/Documents/proto_offline/Karte/drawbot/export/test.png”, 120)

you wrote print = ...
remove the = sign and try again :slight_smile:

The error message below (in red) points you to the problem :wink:

right! How stupid!

Nonetheless it doesn’t seem to work. Why?