Just copy and paste X and Y of anchor

Hi
I want just copy and past X & Y of one anchor to another without paste name or something else. How can I do that? something like paste special for anchor that user can select which parameter want to paste.
Pytone code acceptable :smile:

Select two anchors. The second anchor you select will copy the first selected anchor.

def copy_anchor_position():
	if not len(Layer.selection) == 2:
		return
	for s in Layer.selection:
		if not type(s) == GSAnchor:
			return
	Layer.selection[1].position = Layer.selection[0].position
	
copy_anchor_position()

thank you very much
my mistake: I want copy X & Y from one glyph to another (many) not in the same glyph

maybe 2 pytone code needed
one for copy and one for paste
is it possible?

I don’t understand. You want to copy the anchor position of an anchor in one glyph to an anchor in multiple other glyphs?

Is the anchor name always the same?

No, anchor name is different in glyph (top_1 or top_2 and so) but position is same

for example I want copy anchor position of an anchor top (Just X & X) and paste to other glyph that have top_1 or top_2

Can you explain the use case?

It is used to arrange anchors in ligatures
The anchor coordinates of simple glyphs are used to set the anchor of ligature glyphs with different names
It is also used for use between ligatures

So you want to copy the anchors of the components that are already in the glyph to the same position?


you see these two anchor. I want copy X & Y of top anchor to ligature anchor top_2
for bottom is so

Then you are trying to duplicate the anchor from the component and rename it, correct?

Can you show what you want the anchors in the ligature to look like?

No. Not from component. from a glyph

in this pic X & Y of top_2 and bottom_2 are as same as top and bottom in previous pic

I see.

Try this:

def copy_anchor_position(source_glyph_name):
	source_glyph = Font.glyphs[source_glyph_name]
	for selected_layer in Font.selectedLayers:
		for source_layer in source_glyph.layers:
			for anchor in source_layer.anchors:
				if anchor.name not in ["top", "bottom"]:
					continue
				target_layer = selected_layer.parent.layers[source_layer.associatedMasterId]
				index = 1
				while (new_name := "%s_%s" % (anchor.name, index)) in target_layer.anchors.keys():
					print(new_name)
					index += 1
				new_anchor = anchor.copy()
				new_anchor.name = "%s_%s" % (anchor.name, index)
				target_layer.anchors.append(new_anchor)

copy_anchor_position("a")

As an argument for copy_anchor_position(), pass the name of the glyph from which you want to copy the anchor. The script will then copy the anchor with the same position to all selected glyphs (in all layers), renaming them if they are already present. For example, if you already have top_1 in your target glyph, the script will name the new copied anchor top_2.

Unfortunately not working
Is it impossible to have something like paste special in edit menu?
for example normally coping anchor but when want to paste, on anchore, use paste special for paste X & Y. ?
@mekkablue @GeorgSeifert

What is not working? How are you using it? It works perfectly for me.

Maybe I dont use it correctly
please help me more
I want copy anchor from (reh-ar.fina) to (behDotless_reh-ar.fina.rlig) and (behDotless_reh-ar.rlig)

In text mode (like in your screenshots above), select the glyphs you want to copy the anchors to.

Write the name of your source glyph in the function at the bottom. Like this:

WOW
YOU ARE GOD
thank you very much
till now everything is OK
Can I have more option?


in ligature (seen_reh-ar.liga) code work fine for top_2 and bottom_2
for top_1 and bottom_1 I need calculate X & Y from right corner of glyph
Is it possible?

That’s exactly why I asked earlier. I’ll have a look how easily that can be implemented.