Can not get the component's properties

Test.glyphs (148.4 KB)

mylayer = Glyphs.font.glyphs["py_test"].layers[0]
point = NSPoint(0,0)
i = 1
while  i <= 7:
    mylayer.components.append(GSComponent("X00"+str(i),point))
    i = i + 1
    component = mylayer.components[i-1]
    print component

It’s my script and Glyph file.
The component appended by the script can not position at point(0,0), which can not be printed and be none.
Please help to check the file.
Thanks and regards.

You need to move the line i = i + 1 to the end of the loop.

from Foundation import NSPoint
mylayer = Glyphs.font.glyphs["py_test"].layers[0]
point = NSPoint(0, 0)

for i in range(1, 8, 1):
	component = GSComponent("X00"+str(i), point)
	component.automaticAlignment = False
	mylayer.components.append(component)
	print component

With the line component.automaticAlignment = False it will keep the position in point.

(To get the nice formatting, use three ‘backticks’ or graves before and after the code block. Click on edit to see the code)

One more cleanup. Instead of NSPoint, you can use a tuple

mylayer = Glyphs.font.glyphs["py_test"].layers[0]
point = (10, 0)

for i in range(1, 8, 1):
	component = GSComponent("X00"+str(i), point)
	component.automaticAlignment = False
	mylayer.components.append(component)
	print component

Wonderful.