Duplicate entire master

*edit - fixed a silly error in code but ultimately same result.

I’ve written a little test function to duplicate an entire master prior to performing some actions on those newly created. While it appears to have duplicated them I can’t edit or select them in the layers panel individually. When I delete anyone one of them from the master info panel they all disappear. This tells me their ID is also duplicated and not newly assigned.

When I save and close the file, reopen it and try to delete a master it will allow this. But all the glyphs in newly duplicated masters are empty.

What could I do?

03

My script is processing an existing font and adding new variable font axes. Previously I was adding new master layers. My thought was duplicating the entire master reduces the chance of incompatibility, saves ot features etc.

Same result in 2.4, 2.5, 2.6

def DupeMaster(dupenum):

	print "start dupe"

	font = Glyphs.font
	s = font.masters[0]

	for d in range(dupenum):
		print "dupe" + str(d)

		font.masters.append(s)

DupeMaster(3)

You actually have to copy the master object s.

def DupeMaster(dupenum):
	font = Glyphs.font
	master = font.masters[0]

	for d in range(dupenum):
		print "dupe", d
		masterCopy = master.copy()
		font.masters.append(masterCopy)
		font.copyInfoFrom_sourceFontMasterID_targetFontMasterID_(font, master.id, masterCopy.id)
DupeMaster(3)

The last line is a nice helper to copy all the layers and the kerning.

Aha! Two things… 1) thank you very much, 2) my gappy code bothers you huh?

That monstrously long last function name doesn’t work in 2.4 so you’ve now sold me on 2.6 :slight_smile:

Thanks again Georg. Huge help.