Krita Scripting from "Outside Krita"?

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

Hi

yes and no

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 :slight_smile: )

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 :slight_smile:

Grum999

1 Like

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

Specifically, what I was trying to do is to open a .kra file, and render the animation of the .kra file (in an automated way)

In this case i think you just want to export the animation you don’t even need to open krita just call the command line

Nice, what if I want to automate the change of some things before exporting the anim? (like for example, disable some layers)

Then for that not much you can do other than open krita and automate that there i think

Then make a script for inside of Krita to disable those layers, and use kritarunner to run the script from the commandline.

1 Like

Thanks a lot, and thanks grum999, I think I have the info I need now: kritarunner

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()}')

/AkiR

2 Likes

Thanks, that info helps me a lot , I am on windows

Wait, where I get kritarruner.exe, does it comes included with Krita installation itself ?

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
            ...

/AkiR

Silly me lol

I’ve just found it, time to play with the new shiny toy :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.