Import SVG with stroke width and stroke ends

Hi!
Im trying to write a script to import a sequence of SVGs into glyphs with the stroke widhts and stroke endings intact.
So far I managed to import SVG paths, but it is pretty much the same as using File/Import/Contours. The information about the stroke attributes is lost and they are interpreted as shapes.

What I would like to achieve would be similar to when you copy and paste a path from e.g. Illustrator. Here the paths have strokes, but no stroke endings. Ideally the stroke endings would also be imported.

Do you know how this could be done?

This is the code I have used so far:

import os
from Foundation import NSURL
thisFont = Glyphs.font

directory = "/SVG_test/svg/"

for fileName in os.listdir(directory):
	if fileName.endswith(".svg"):
		svgFilePath = directory+fileName
		#print(svgFilePath)
		svgFileUrl = NSURL.alloc().initFileURLWithPath_(svgFilePath)
		
		glyphName = fileName.replace(".svg","")
		#print(glyphName)
		
		activeLayer = thisFont.selectedFontMaster.id
		#print(activeLayer)
		layerOfGlyph = thisFont.glyphs[glyphName].layers[activeLayer]
		
		layerOfGlyph.importOutlinesFromURL_scale_error_(svgFileUrl, 1, None)

I hoped that importOutlinesFromURL_scale_error_() could maybe help me, but I couldn’t find out more about how it works in the docu …
I imagine that I’d need to parse the SVG to find out the stroke widths and attributes of each path, but I’m not sure if this is possible.

I also couldn’t find any info about stroke endings in the docu … Is there a way to apply them programmatically?

Can you try the latest cutting edge version? And if that doesn’t work, can you send me a sample file.

I’m always on the cutting edge version. :wink:

Actually, I think I found a solution for my problem without any coding required. The built in vector import correctly interprets stroke thickness and stroke ends/caps if they are included in the SVG as an attribute (style tags don’t work). To make sure that is the case, I just had to choose the correct export settings in Illustrator. :upside_down_face:

I was able to import all icons with correctly applied strokes in one go. :blush: