Adding attributes to existing classes

Hi! Is it possible to add attributes to existing classes? I’d need “axes” for special layers, so tried something like this:

setattr(GSLayer, “axes”, None)
for glyph in thisFont.glyphs:
    if layer.isSpecialLayer is True:
        layer.axes = [value]

But the attribute is read-only, can’t find a way to override it. Is there any way to achieve that? Thanks!

As this values don’t survive a restart anyway you might be better of using proper API.

layer.setTempData_forKey_(value, "axes")

print(layer.tempDataForKey_("axes"))

I added it to the wrapper, so in the next version you can use:

layer.tempData["axes"] = value

print(layer.tempData["axes"])

But if you really need the property:

GSLayer.axes = property(lambda self: self.tempDataForKey_("axes"),
				lambda self, value: self.setTempData_forKey_(value, "axes"))
1 Like

Amazing, thank you!

May I also ask is there any difference what master a special layer belongs to? Is it just the matter of the user interface, or does it make some difference in interpolation?

The for brace layers it is not important to what master they belong.

May I ask what you are trying to do?

1 Like

It’s for a script that cuts a variable font in smaller parts. Nearly there!