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 ?