openBezierPath won’t return a path object, even though bezierPath does

I’m working on a simple DrawBot script to draw a glyph’s outlines into a PDF/etc for presentation purposes, for some students I am helping to teach about Glyphs & type design.

Unfortunately, I am so far only able to output a glyph with overlap removed. If I try to utilize openBezierPath or completeOpenBezierPath, I get a NoneType instead of a path.

As a simplified example, if I run the following in the GlyphsApp DrawBot plugin or Macro Panel…

from GlyphsApp import *

font = Glyphs.font

layerId = Glyphs.font.selectedLayers[0].layerId
layerGlyph = Glyphs.font["g"].layers[layerId]

print("bezierPath is ", type(layerGlyph.bezierPath))    
print("openBezierPath is ", type(layerGlyph.openBezierPath))

…it outputs the following:

bezierPath is  <objective-c class GSSaveBezierPath at 0x102d67920>
openBezierPath is  <class 'NoneType'>

I have experimented with various permutations of this code, but can’t seem to output paths with overlaps.

Further, it seems that these might be documented incorrectly in the API docs. For one, I can use .bezierPath only without .fill(). If I try to add .fill() or .stroke() to layerGlyph.openBezierPath, I get this:

Traceback (most recent call last):
  File "<untitled>", line 9, in <module>
AttributeError: 'NoneType' object has no attribute 'stroke'

This issue seems to have been mentioned once before, but without resolution:

Am I misunderstanding something? That is usually the case in errors like this. :smile:

Thanks for any insights!

The open bezierpath accessors contains all not closed paths. If you don’t have open paths, those will be empty or none.

This code will give the basic outlines:

bez = NSBezierPath.new()
for shape in Layer.shapes:
	shape.drawSimpleInPen_(bez)
print(bez)