Expand outline with a script only for unclosed paths

Hi. I have a glyph with a mixed paths types – an already closed paths that I don’t want to touch, and unclosed paths with a stroke width which I want to expand. The design is pretty complicated and there are a lot of paths, so It’s not easy to manually select an unclosed ones.

Here’s what I tried:

for path in Layer.paths:
	if not path.closed and path.attributes['strokeWidth']:
		path.flattenOutlines()

An error:

'GSPath' object has no attribute 'flattenOutlines'

I also tried path.expandStroke() and path.expandedStroke() that also follow to a similar errors. I will be grateful for any help.

Check the Method Reporter plugin from mekkablue, it will give you more clues as to which methods exist and which don’t.

GSLayer has the following:
flattenOutlines()

GSPath has these:
flattenendOutlines() (this has a typo, btw, it should be flattenedOutlines() @GeorgSeifert )
expandedStroke()

Maybe these methods yield what you are looking for.

I fixed that typo an hour ago.

Thanks Sebastian.
Unfortunately, neither flattenendOutlines() / flattenedOutlines() nor expandedStroke() works at the moment, although the last one does not cause an error in the Macro.

Currently I use the following script to select all an unclosed paths with a stroke width, and then expand it manually. I’m fine with that.

Layer.clearSelection()
Glyphs.font.disableUpdateInterface()

for shape in Layer.shapes:
	if not shape.closed and shape.attributes['strokeWidth']:
		for node in shape.nodes:
			Layer.selection.append(node)

Glyphs.font.enableUpdateInterface()

I needed to add some API to make this possible. Will be in the next update.

Thanx!

@GeorgSeifert I’m on 3.2.3 … Did you happen to add a method for this, yet? It’s not super urgent if not, but I have been seeing these paths pop up lately in fonts I need to build with FontMake, so it would be handy to have a method to flatten/expand paths like this.

I adapted Michael’s script slightly to find glyphs containing paths in need of expanding. Here’s what I have so far:

for glyph in Font.glyphs:
	for layer in glyph.layers:
		for shape in layer.shapes:
			if shape.shapeType == 2 and shape.closed == False and shape.attributes['strokeWidth']:
				print(layer)
				# question: can you expand the paths in a method?

For now, I have a manageable number of paths to just manually expand, one glyph at a time. But, I bet I’ll have to build a font with many special paths like this, someday soonish.

One other related note: I initially tried finding all such glyphs with a Smart Filter, which often works for stuff like this (“Has Special Layers,” “Has Metrics Keys,” etc). Is it there and I’m missing it? If not, it would be handy to have in the future. (I see that a “custom” filter is possible, but I’m not quite sure how to use that syntax, and the docs linked in the “?” icon are slightly daunting…)

Thanks!