It seems that I can’t get any layers from an instance that is not added to Font.instances with interpolatedFontProxy
.
Example:
def make_instance(*values):
i = GSInstance()
i.font = Font
for x in range(len(i.axes)):
i.axes[x] = values[x]
return i.interpolatedFontProxy
interpolatedFont = make_instance(50) #or any available value
print(interpolatedFont.glyphs['a'].layers[0]
would print None. Adding the instance to Font.instances fixes it, but I’d rather not do that, nor use interpolatedFont. Any idea?
print(interpolatedFont.glyphs['a'].layers[interpolatedFont.fontMasterID()])
or
print(interpolatedFont.glyphs['a'].layers[interpolatedFont.masters[0].id)])
But the index should work, too. I’ll have a look.
The problem is that the instance gets deallocated when your function returns. So you need to store it somewhere until you are done. A global list will do the trick.
instances = []
def make_instance(*values):
i = GSInstance()
instances.append(i)
i.font = Font
for x in range(len(i.axes)):
i.axes[x] = values[x]
return i.interpolatedFontProxy
interpolatedFont = make_instance(50) #or any available value
print(interpolatedFont.glyphs['a'].layers[0])
1 Like
Thanks Georg! I think I get the general logic behind this (the actual instance object doesn’t exist outside the scope of the function) but then, shouldn’t I just be unable to access anything via interpolatedFontProxy
? I could still get some stuff, like glyphs, or the master, but just not layers.
In my particular case, I guess it’ll be easier to just have the function return the instance instead. Why didn’t I think of that before, well… ¯\(ツ)/¯
def make_instance(*values):
i = GSInstance()
i.font = Font
for x in range(len(i.axes)):
i.axes[x] = values[x]
return i
instance = make_instance(50)
interpolatedFont = instance.interpolatedFontProxy
print(interpolatedFont.glyphs['a'].layers[0])
1 Like
The proxy needs the instance now and then.
1 Like