SVG sequence import using a script (for a folder of SVGs)

Hi,

I want to make a script that will import a sequence of SVG files (named A.svg, B.svg, and so on) from a folder into corresponding glyphs in Glyphs. I have pieced together some code but unfortunately it imports the SVG code into the same glyph (the paths are on top of one another).

import os

input_folder = '/path/svg_folder'

font = Glyphs.font
for root, dirs, files **in** os.walk(input_folder, topdown= False):
for name in files:
    if name != '.DS_Store':
        path = os.path.join(root, name)
        base = os.path.basename(path)
        glyph_name = os.path.splitext(base)[0]
        glyph = font.glyphs[glyph_name]
        glyph.selected = True
        Importer = GSSVGtoPath.alloc().init()
        Importer.readFile_toLayer_error_(NSURL.fileURLWithPath_(path), Layer, None)

What am I doing wrong?

The last line has a “Layer” parameter. You need to put in the layer you like the path to go to.

import os

input_folder = '/path/svg_folder'

font = Glyphs.font
for root, dirs, files **in** os.walk(input_folder, topdown= False):
for name in files:
    if name != '.DS_Store':
        path = os.path.join(root, name)
        glyph_name = os.path.splitext(name)[0]
        glyph = font.glyphs[glyph_name]
        glyph.selected = True
        Importer = GSSVGtoPath.alloc().init()
        layer = glyph.layers[font.selectedFontMaster.id]
        Importer.readFile_toLayer_error_(NSURL.fileURLWithPath_(path), layer, None)

But this functionality is already build in. In Font View, Edit > Import > Outlines… It will use the names of the files to pick the glyphs just as your script.

Of course, yes the layer! Thanks.

I had tried the Import function but not with multiple files - I guess one of those times of trying to script before checking the full functionality.