Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weiweihuanghuang/eff1629de0d9bbe9cc2e to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/eff1629de0d9bbe9cc2e to your computer and use it in GitHub Desktop.
Set Transform Origin to Centre of Selection
#MenuTitle: Set Transform Origin to Centre of Selection
# -*- coding: utf-8 -*-
__doc__="""
Sets origin point for Rotate tool to the centre of the selection.
"""
import GlyphsApp
Font = Glyphs.font
Doc = Glyphs.currentDocument
selectedLayer = Font.selectedLayers[0]
try:
# until v2.1:
selection = selectedLayer.bounds()
except:
# since v2.2:
selection = selectedLayer.bounds
newOriginX = selection.origin.x+selection.size.width/2
newOriginY = selection.origin.y+selection.size.height/2
newOriginPoint = NSPoint( newOriginX, newOriginY )
myController = Glyphs.currentDocument.windowController()
myController.graphicView().setNeedsDisplay_(False)
rotateToolClass = NSClassFromString("GlyphsToolRotate")
myRotateTool = myController.toolForClass_( rotateToolClass )
myRotateTool.setTransformOrigin_( newOriginPoint )
myController.graphicView().setNeedsDisplay_(True)
# print newOriginPoint
# print selection.origin.x, selection.origin.y, selection.size.width/2, selection.size.height/2
# except Exception, e:
# # brings macro window to front and reports error:
# Glyphs.showMacroWindow()
# print "Set Transform Origin Error: %s" % e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment