The automation capabilites of Krita are extremly useful to me.
I’ve learned how to create python scripts to automate lot tedious and repetitive tasks
Those are executed on Krita runtime enviroment, or “inside krita”
I wonder if there is a way to execute those from outside Krita, like for example, running a python script from outisde krita that opens a .kra file, make some automated changes and save that file
You can execute a python krita script from command line with kritarunner I think (didn’t tested it from a long time now and it’s blurry in my memory )
You can manipulate a krita file from any script as .kra file are zip files
But you have to now how to decode/encode content.
Not so difficult but takes times to write a such tools (I know what I’m talking about, I already started to write decoder fro Buli Commander but no time for ,now to write a complete decoder…)
Importing python krita library outside krita is probably possible, but might need some technicals skills and I don’t know how
I think depending on what you want to automate you can do it with pure python or even a shell script. As for example you can open a kra file by calling krita from the command line passing the kra path too.
Though i don’t know if it would be possible to chain opening Krita and then calling another script
if you are running on Windows, kritarunner is little bit strange…
"""
Important on Windows this script must be placed to:
%APPDATA%/kritarunner/hello_krita_runner.py
how to run from cmd:
"<path to kritarunner.com>" -s hello_krita_runner "some" "arguments" "for" "script"
Note:
-s expects an module name that can be imported to pykrita,
in other words filepath to script WILL NOT WORK!!!
(also paths in PYTHONPATH are normally ignored by pykrita)
replace <path to kritarunner.com> with something like C:\Program Files\Krita (x64)\bin\kritarunner.com
(the actual path depends on where krita was installed.) or if krita\bin is included to PATH, then kritarunner.com can be used without absolute path prefix.
"""
from krita import Krita
def __main__(*args):
app = Krita.instance()
print(
f'Hello from Krita runner!\n'
f'args = {args}\n'
f'krita version = {app.version()}')
kritarunner.exe & kritarunner.com come with krita installation.
kritarunner should be located next to krita.exe.
Program Files\ * can be different (depends on installation)
krita (x64)\ * can be different (depends on installation)
bin\
krita.exe
kritarunner.exe
kritarunner.com
...