Move components

Hey guys, Does anyone know if there is a way to shift the position of components inside multiple selected glyphs?

Thanks a lot!

Do you want to shift all components or only specific components (say, all components with a certain name) in the selected glyphs?

It depends. Sometimes all, sometimes only selected components. If possible. Thank you!

Run the following code in the Macro Panel to move all components in all selected layers:

for layer in Font.selectedLayers:
	for component in layer.components:
		component.automaticAlignment = False
		x, y = component.position
		component.position = (x, y + 100)

Here, I move all components up by 100 units and maintain the x coordinate. Change as needed.

If you only want to work on certain components, run the following code:

for layer in Font.selectedLayers:
	for component in layer.components:
		if component.name == "B":
			component.automaticAlignment = False
			x, y = component.position
			component.position = (x + 50, y - 25)

Here, I check the component name to move, for example, only the B components.

Awesome! Thank you so so much! That helps! Is there a way to move different components in multiple glyphs? Maybe I can add more glyph names next to the “B”? Thanks again. Much appreciated.

Yes, here is an example that works on multiple different components:

for layer in Font.selectedLayers:
	for component in layer.components:
		if component.name in ["B", "comma", "_part.arch"]:
			component.automaticAlignment = False
			x, y = component.position
			component.position = (x, y + 500)

for layer in Font.selectedLayers:
for component in layer.components:
if component.name in [“B”, “comma”, “_part.arch”]:
component.automaticAlignment = False
x, y = component.position
component.position = (x + 50, y - 25)

Thank you! I tried to move the components, and the components are not moving to the right place like in the previous codes. Any idea why it’s happening? Thanks a lot!

*I editd the last line because the x and y are different.

What is happening now and what should happen instead? Can you share screenshots of the before and after?

I’m not sure… Now it worked… I’ll play with it more and let you know… Thanks a lot for the help! Truly appreciated.

Something weird… on the first time I’m applying the code on the glyphs, it works. on the second time, it takes the component to a different direction…

That is weird. Are you sure you did not change the last line which controls how much the components are moved along the x and y axis? The direction should not change when running the macro multiple times.

Yes, I did change it, because I need a different X and Y… So I used: component.position = (x + 50, y - 25) instead of component.position = (x, y + 500)… But I didn’t change the values… weird.

This is difficult to reproduce. Can you do a screen recoding of you running the macro and the components moving? Or a series of screenshots? You can also send me them as a private message on this forum so your work is not public.

Sure. will do. Thank you. I’ll prepare that for you. Thanks a lot!