Flipping Path not at center

I’m looking for a way to flip paths according to the selected point in the transformation-tool with a script. I found a script to flip, but it does only at the center of the selection.
Can I change any of these lines to flip at the bottom or at the right side?

I think, these are the essential code-lines for flipping:

selectionYList = [ n.y for n in selection ]
lowestY, highestY = min( selectionYList ), max( selectionYList )
diffY = abs(lowestY-highestY)
midY = highestY - diffY/2


sortedSelection = sorted( selection, key=lambda n: n.y)
for thisNodeIndex in range( len(selection)):
	sortedSelection[thisNodeIndex].y = sortedSelection[thisNodeIndex].y-(sortedSelection[thisNodeIndex].y-midY)*2


selectionXList = [ n.x for n in selection ]
leftMostX, rightMostX = min( selectionXList ), max( selectionXList )
diffX = abs(rightMostX-leftMostX)
midX = rightMostX - diffX/2


sortedSelection = sorted( selection, key=lambda n: n.x)
for thisNodeIndex in range( len(selection)):
	sortedSelection[thisNodeIndex].x = sortedSelection[thisNodeIndex].x-(sortedSelection[thisNodeIndex].x-midX)*2

There are two options:
use the method the transform panel is using

GlyphsPaletteTransform.transform_identifier_checkSelection_shiftKey_(layers, "flipVertical", checkSelection, False)

or this:

transform = NSAffineTransform.new()
transform.translateXBy_yBy_(transformOrigin.x, transformOrigin.y)
transform.scaleXBy_yBy_(-1, 1) # flip those numbers to flip the other direction
transform.translateXBy_yBy_(-transformOrigin.x, -transformOrigin.y)
layer.transform_checkForSelection_(transform, checkSelection)

(then you need to check path direction yourself)

Thanks, but I don’t know where to insert this code. When I replace the code above with your code, nothing happens. It’s the same, when I insert these line into the macro-window.

Sorry, I have absolutly no experience with python and coding. :thinking: