I am wondering if there is a more efficient way to write this snippet for applying a specific transformation (shifting 2 units to the right, in this case) for a selected path but for only a select set of masters.
my_masters = []
for name in [
"Regular Light",
"Ultra Light",
"Regular Light Italic",
"Ultra Light Italic",
]:
for master in Font.masters:
if master.name == name:
my_masters.append ( master )
theseLayers = []
for m in my_masters:
layer = Font.glyphs[gname].layers[m.id]
theseLayers.append( layer )
transform = NSAffineTransform.new()
transform.translateXBy_yBy_(2, 0)
for thisLayer in theseLayers:
for node in thisLayer.selection:
node.position = transform.transformPoint_(node.position)
It’s pieced together from mekkablue Lines by Master and a transform snippet by Florian
Ah, and actually just looking back at your previous snippet for looping through masters, and seems like it would be faster to directly list the masters + index rather than looping through every time.
But if you use affine transformation, you can apply it to the whole layer at once with layer.applyTransform(matrix). I assume that’s going to be faster.
Now all that’s left is to properly format your code (because Rainer’s objectiveC habits result in very PEP-unconform code )
Variables are always written lowercase with underscores (so these_layers instead of theseLayers), and you need a space around your maths operators, so node.x += 2. Also, no spaces before or after parentheses.