what I am trying to achieve with is :
- Open some random image
- Selection ( manual or auto )
- Copy contents of selection
- Create a new Layer
- Paste content into the new layer
- Select new layer as active layer
- mirror node the new layer
- merge down the new layer over the original layer
Selections :
- Manual - there is a selection done previously to running the script
- Auto - there is no current selection made so a selection needs to be made by the script
Sample Code so far
from krita import *
def Wait():
ad = Krita.instance().activeDocument()
ad.waitForDone()
ad.refreshProjection()
cond = "Left"
# Variables
ki = Krita.instance()
ad = ki.activeDocument()
node = ad.activeNode()
name = "Mirror Fix : " + node.name()
width = int( ad.width() )
height = int( ad.height() )
w2 = width * 0.5
h2 = height * 0.5
value = 255
# Force the Mirror Axis to Center
ki.action('mirrorX-moveToCenter').trigger()
# Selection
ss = ad.selection()
if ss == None:
# Variables
px = 0
py = 0
pw = w2
ph = height
# Select Area
sel = Selection()
sel.select( px, py, pw, ph, value )
ad.setSelection( sel )
else:
# Variables
sel = ss
px = sel.x()
py = sel.y()
# Copy
sel.copy( node )
sel.clear()
# New Node
new_node = ad.createNode( name, "paintLayer" )
ad.activeNode().parentNode().addChildNode( new_node, node )
# Paste
sel.select( 0, 0, width, height, value )
sel.paste( new_node, px, py )
Wait()
# Active Layer
ad.setActiveNode( new_node )
Wait()
# Mirror Node
ki.action('mirrorNodeX').trigger()
Wait()
# Merge (this solves a alpha compositing issue)
merge_node = new_node.mergeDown()
Wait()
I am currently like one action away to be able to make the thing run but I there is something missing.
I get the feeling once I create the new layer something is lost on the way and then commands that work under normal conditions stop working.
Currently if you do no selection the script will work and mirror the image, but if you make a manual selection with freehand for example the script will break and not flip properly.