Glyphs 3 can’t loop through masters or instances

I’ve tried the code below in a few files created in Glyphs 2 and I always get a 'float' object is not callable error. It doesn’t matter if I convert the files to Glyphs 3 format, the error remains.

Glyphs.clearLog()
font = Glyphs.font

try:
	print("font.masters:")
	print(font.masters)
except Exception as e:
	print(e)

print()

try:
	print("font.instances:")
	print(font.instances)
except Exception as e:
	print(e)

print()

try:
	print("loop through font.instances:")
	for instance in font.instances:
		print(instance)
except Exception as e:
	print(e)

This is the result:

font.masters:
'float' object is not callable

font.instances:
(
    "<GSInstance 0x600003282c40> Regular (74.0)",
    "<GSInstance 0x600003281b00> SemiBold (98.0)",
    "<GSInstance 0x6000032800c0> Bold (118.0)"
)

loop through font.instances:
'float' object is not callable

That error is due to an change in the API, not caused by the origin of the file. I fixed it.

Perhaps this would be better:

font = Glyphs.font
for master in font.masters:
        print(master.name)
        
for instance in font.instances:
        print(instance.name)

Thanks!

I’ve also noticed some properties of GSInstance are broken in build 3040:

  • familyName
  • fontName
  • fullName
  • preferredFamily
  • preferredSubfamilyName
  • windowsFamily
  • windowsStyle
  • windowsLinkedToStyle

All of them return something like:

AttributeError: No selector [fontName...]

Absolutely. The original piece of code was just an example to show which pieces of the API were broken, not something to be used for anything else.

1 Like

Thanks for the report. I fixed it.

1 Like

Thanks for fixing this!

One last thing: in build 3042, the fontName and fullName properties return only the first character of the string.

In a related subject, I was trying to export a file that had errors in the smcp feature (forgot to update the feature after renaming some glyphs) using the generate() function. It obviously exported nothing, but it didn’t throw me an error. In fact, the function returned True.

Can you show the code that uses fontName and fullName?

I’ll have a look at the generate function.

I created a new file, added one instance and run the following:

for instance in Glyphs.font.instances:
	print(instance.fontName)

The output is:

N

instead of:

NewFont-Regular

You didn’t say that it was on the instances :wink:

Edit: fixed it.

1 Like