Python - Copy Paste with diferent Selection inputs

I was working on a simple script to take in the selection of a user and then copy a mirror of it to the other side of the layer.

This was my progress so far ( should require something on screen to be selected already):

from krita import *

# Krita Instance Objects
ki = Krita.instance()
ad = ki.activeDocument()
an = ad.activeNode()
ss = Selection()
root = ad.rootNode()

# Copy Selection for Horizontal Flip
ad.selection()
ad.setSelection(ss)
ss.copy(an)

# Create Layer
name = "Mirror Node"
mn = ad.createNode(name,"paintlayer")
cn = root.addChildNode(mn,an)
anc = ad.setActiveNode(mn)

# This Code is Dependant of the Mirror Axis being in the Center of the Image
# Deselect image so the mirror Operation affects the layer and not just the Selection
Krita.instance().action('deselect').trigger()
ss.paste(mn,0,0)
Krita.instance().action('mirrorNodeX').trigger()

# Merge Down
mn.mergeDown()

# Clean up
ad.refreshProjection()

However it is not able to actually grab the currently active selection from the user and then it pastes nothing on the new layer I create after.

I did a similar script before, but where no input selection is needed so it considers one half of the screen to mirror to the other side all together ( this one is working) :

from krita import *

# Krita Instance Objects
ki = Krita.instance()
ad = ki.activeDocument()
an = ad.activeNode()
ss = Selection()
root = ad.rootNode()

# Read document size
width = ad.width()
height = ad.height()
# Read mirror Tool position
w2 = (width / 2)    # Left-Right
h2 = (height / 2)   # Top-Bottom

# Copy Selection for Horizontal Flip
xx = 0
yy = 0
ww = w2
hh = height
value = 255
ss.select( xx,yy,ww,hh,value )
ad.setSelection(ss)
copy = ss.copy(an)

# Create Layer
name = "Mirror Node"
mn = ad.createNode(name,"paintlayer")
cn = root.addChildNode(mn,an)
anc = ad.setActiveNode(mn)

# This Code is Dependant of the Mirror Axis being in the Center of the Image
# Deselect image so the mirror Operation affects the layer and not just the Selection
Krita.instance().action('deselect').trigger()
ss.paste(mn,0,0)
Krita.instance().action('mirrorNodeX').trigger()

# Merge Down
mn.mergeDown()

# Clean up
ad.refreshProjection()

If i make a ss.select( xx,yy,ww,hh,value ) it creates a working selection to be used by the Selection class but if a selection is already made on screen, I am not sure how to actually get that info and operate on it.
What am I doing wrong ?

Have you tried first copying the content of the selection, and then setting the empty selection? Also why do you set an empty selection and then deselect everything again anyway?

Ahh wait… I think you misunderstood the API a bit;
I would write it more like this (disclaimer: I haven’t check the code in practice):

# Krita Instance Objects
ki = Krita.instance()
ad = ki.activeDocument()
an = ad.activeNode()
## here the first change: - selection() returns the current selection (I think...)
ss = ad.selection()
root = ad.rootNode()

# Copy Selection for Horizontal Flip
## second change - let the current selection copy the content
ss.copy(an)

# Create Layer
## no change here but I wouldn't be surprised if it wasn't needed and ss.paste() would create this node on its own, just with a different name
name = "Mirror Node"
mn = ad.createNode(name,"paintlayer")
cn = root.addChildNode(mn,an)
anc = ad.setActiveNode(mn)

# This Code is Dependant of the Mirror Axis being in the Center of the Image
# Deselect image so the mirror Operation affects the layer and not just the Selection
Krita.instance().action('deselect').trigger()
ss.paste(mn,0,0)
Krita.instance().action('mirrorNodeX').trigger()

Btw, it would be easier to read if you used more English-like words instead of initials as variable names.

Truth be told I don’t really know what I am doing, I am just trying to do it somehow ‘~’

With the difference it is pasting a empty layer.

no I haven’t, but that is possible?

I do it so I can use the “mirrorNodeX” on the entire layer and not just on the selection that was made.

I think the issue might be on the PASTE command. the Copy places the image on the clipboard correctly by the looks of it.