Help me on script

here is a script for copy shapes from one glyph and paste to another glyph with same coordinates from left or right
but it didn’t paste selected and copied part, it paste complete source glyph
Is it possible just selected shape paste in glyph or not?

# MenuTitle: Copy & Paste Selected Shapes
# -*- coding: utf-8 -*-
from AppKit import NSPasteboard, NSUTF8StringEncoding
from Foundation import NSString
import GlyphsApp

Glyphs.clearLog()

def paste_shapes_keep_coordinates(measure_from_right=False):
    pasteboard = NSPasteboard.generalPasteboard()
    typeName = pasteboard.availableTypeFromArray_(["Glyphs elements pasteboard type"])
    if typeName == "Glyphs elements pasteboard type":
        Data = pasteboard.dataForType_(typeName)
        theText = NSString.alloc().initWithData_encoding_(Data, NSUTF8StringEncoding)
        Dictionary = theText.propertyList()
        if Dictionary is not None:
            source_glyph_name = Dictionary['glyph']
            source_glyph = Glyphs.font.glyphs[source_glyph_name]
            
            for source_layer in source_glyph.layers:
                copied_paths = [path.copy() for path in source_layer.paths]
                
                for sel_layer in Glyphs.font.selectedLayers:
                    target_layer = sel_layer.parent.layers[source_layer.layerId]
                    if not target_layer:
                        continue

                    for path in copied_paths:
                        new_path = path.copy()
                        target_layer.paths.append(new_path)

                        if measure_from_right:
                            offset = target_layer.width - source_layer.width
                            for node in new_path.nodes:
                                node.x += offset

# Copy shapes and run the script to paste them to all selected layers
paste_shapes_keep_coordinates(measure_from_right=True) # Set to True or False as needed

This part goes to the original glyph where you copied from:

            source_glyph_name = Dictionary['glyph']
            source_glyph = Glyphs.font.glyphs[source_glyph_name]
            
            for source_layer in source_glyph.layers:
                copied_paths = [path.copy() for path in source_layer.paths]

instead of using whatever was on the clipboard.

What exactly are you trying to do with that script?
As fare as I can see, pressing Cmd+V should do what you want.

Cmd+V paste in one layer and with script I want do for all layer in correct coordinate from right or left
however it didnt work

Traceback (most recent call last):
  File "<macro panel>", line 18
NameError: name 'source_glyph_name' is not defined

please check script with 2 different glyph with some layer
copy one part and run script in other glyph

What you have to do is instead of looking at the original glyph and copy its paths, look in the Dictionary for whatever was copied.
Or, you have to check the layer you copied form and check what paths have selection.

thanks :pray: