Scripting: rotate selection

Hi! I’m trying to write a script that would simply rotate the selected nodes by a certain degree.
With very basic understanding, I’m just tweaking a piece of code from the tutorials, but can’t make it to rotate only the selected nodes, not the whole layer. Could you please help?

Here’s what I have so far:

Mekkablue has a script called “Rotate Around Anchor” whose idea is to make things like asterisk from one shape. You can see in the code that rotation needs a little more work, especially something called NSAffineTransform for which you can set rotation angle ( rotationTransform() ). The rotation happens from the origin point of the selection and the outline may seem to appear to move its position. To compensate for that, you move the outline to the desired centre position, rotate, and move it back.

1 Like

Here is a Python scripting tutorial that explains Affine Transformations:

In the Python for Glyphs repo, there is a transform snippet that give you a handy method.

1 Like