How to trigger "flip" method from palette in a script

I am struggling to try to code the “flip horizontal” and “flip vertical” methods from the Glyphs Palette. Is there an easy way to trigger them in a script?

I know @alexs did these scripts, but they don’t work as expected in all situation (typically when a component scale is [100%/-100%])

from Foundation import NSAffineTransform, NSMidX, NSMidY

def flip(layer, scaleX=1, scaleY=1):
	bounds = layer.boundsOfSelection()
	transform =
	transform.translateXBy_yBy_(NSMidX(bounds), NSMidY(bounds))
	transform.scaleXBy_yBy_(scaleX, scaleY)
	transform.translateXBy_yBy_(-NSMidX(bounds), -NSMidY(bounds))
def flipHorizonally(layer):
	flip(layer, scaleX=-1)
def flipVertically(layer):
	flip(layer, scaleY=-1)

1 Like

Thanks for the report, fixed my scripts too!

1 Like