This works ![]()
from krita import *
app = Krita.instance()
doc = app.activeDocument()
def func():
if not doc:print("no active document");return
steps = [
lambda: (
app.action('merge_layer').trigger(), #make sure to put commas in the expression
print("merging first time")
),
lambda: (
action := app.action('merge_layer'), #create a variable with "walrus operator"
action.trigger(),
print("merging 2nd time")
),
]
delay_per_step = 100 # milliseconds
for i, step in enumerate(steps):
QTimer.singleShot(delay_per_step * (i + 1), step)
func()
It uses timers. Save your your work before trying it! I’ve not found things to execute out of order yet, but 100ms is a long time for most operations in Krita. Adjust the delay accordingly.
See this post for another example that uses regular functions not lambda expressions, so you don’t need the walrus operator. Same timer rule applies. Everything within function/lambda expressions is in its own scope. Ask any chatbot to explain what it all means ![]()