Return a RoboFab glyph object for the currently selected *layer*

like CurrentGlyph() but for the current layer (or master) at least?

def CurrentLayer():
	"""Return a RoboFab glyph object for the currently selected layer."""
	Doc = Glyphs.currentDocument
	try:
		Layer = Doc.selectedLayers()[0]
		return RGlyph(Layer)
	except: pass
	
	print "No glyph selected!"
	return None

Returns this error though:

  File "~/Library/Application Support/Glyphs/Scripts/objectsGS.py", line 426, in __init__
    _GSGlyph.setLayer_forKey_(self._layer, self._layerID)
AttributeError: 'NSKVONotifying_GSLayer' object has no attribute 'setLayer_forKey_'

I’d like to do this so I can make my Robofab pen script work across different masters.

The RGlyph()expects a GSGlyph as argument. Robofab does not distinguish between glyphs and layers. So the Robofab wrapper works with a GSGlyph but points all operations to the layer internally. For that the RGlyph initializer has an extra masterIndex argument.