Centre Anchors Script

Hi everybody,

I’d like to modify a script (mekkablues: “Selection to Center”) to center anchors within the layer-width. (Im coder newbe)

The script run and also can centre in a two-anchored-glyph.

How can I achieve to run the script over more than one selected glyph? Script just run through first glyph of selection.

#MenuTitle: Anker zentrieren

-- coding: utf-8 --

recourse to the script “selection to center” of mekkablue

Align Anchors to the Horizontal Center.

import GlyphsApp

Font = Glyphs.font
Doc = Glyphs.currentDocument
selectedLayer = Font.selectedLayers[0]
selectedGlyph = selectedLayer.parent.name
layerCenter = selectedLayer.width // 2

print “”“Centered anchors. Deviations from center:
(- left / + right)

selection = selectedLayer.anchors


for selectedNode in selection:
	myCenter = round(layerCenter - selectedNode.x)
	print (round(selectedNode.x) - layerCenter), "in", selectedGlyph, selectedNode.name, " " 
	selectedNode.x += myCenter

except Exception, e:
print e

import GlyphsApp

Font = Glyphs.font
Doc = Glyphs.currentDocument

print “”“Centered anchors. Deviations from center:
(- left / + right)


for thisLayer in Font.selectedLayers:
(tab)thisGlyph = thisLayer.parent.name
(tab)layerCenter = thisLayer.width // 2

(tab)for thisAnchor in thisLayer.anchors:
(tab)(tab)myCenter = round(layerCenter - thisAnchor.x)
(tab)(tab)print (round(thisAnchor.x) - layerCenter), “in”, thisGlyph, thisAnchor.name, " "
(tab)(tab)thisAnchor.x += myCenter

(tab)except Exception, e:
(tab)(tab)print e

Thank you. I have to deal with it more :slight_smile:

I think it can be simplified like: thisAnchor.x = layerCenter
I haven’t tried, but this should do what you want, right?

For manual alignment regarding anchors, there is a way. If you select two nodes (no matter if they’re off- or on-curve) and an anchor, it will be centre-aligned between the nodes.

I will try. I know the 3-Point Trick but first of all I was looking for a ‘global’ method. Thanks again.

if you hit cmp+opt+U Glyphs will regenerate the anchors in its default positions. And for the top and bottom anchor that would be the center.

this command was exactly what I was looking for.
Does it work if I select more than one glyph?

But script also works fine.

thanks again to you both

Many menu commands are executable (on multiple glyphs) from the font view.

Try it. :-)

yes it does :slight_smile: