Script help request: adjusting scaling on corner components

I have a bunch of corner components (serifs) with horizontal scaling at various settings. I want to set them all at 100% or -100%. I’m certain scripting will be less painful then going and clicking on all those nodes and resetting the scaling, but I don’t have any scripting skills.
What would a script look like that could reset all negative scales to -100% and all positive scales to 100% on all corner components in all masters of selected glyphs?

for g in Glyphs.font.glyphs:
    for l in g.layers:
        for corner in l.hints:
            originalX, originalY = (corner.scale()[0], corner.scale()[1])
            if corner.scale()[0] < 0:
                corner.setScale_((-1.0, originalY))
                corner.setScale_((1.0, originalY))
            if corner.scale()[1] < 0:
                corner.setScale_((originalX, -1.0))
                corner.setScale_((originalX, 1.0))

I would write it like that:

for g in Glyphs.font.glyphs:
	for l in g.layers:
		for corner in l.hints:
			originalX, originalY = corner.scale()
			originalX = -1 if originalX < 0 else 1
			originalY = -1 if originalY < 0 else 1
			corner.setScale_((originalX, originalY))

Thanks so much guys. For whatever reason, the first script wasn’t making the changes but the second one did.

Curious. Apart from being less elegant, it should be doing the exact same job…
Anyway, glad you solved it!

The snippets use different indentation (spaces/tabs) here. CopyPaste might have lead to an error on the machine of @eliason with Tosche’s space style.

About the indentation. There are two options to trigger a code block. One is to indent the hole block and the second is to put three graves in the line before and after.

this is obvious nicer as you can copy paste the working code without the need to add spaces.

very handy, just what i needed…

@georg, how would it look if u also want all corners to be in center mode

The alignment of a corner component is determined with its options attribute:

Layer.hints[0].options = 2

0 = left aligned
1 = right aligned
2 = centered

1 Like