Python API - lots of noob questions

Hi, I’m a beginner in Krita scripting too, but I guess I know the answers to your questions.
Basically python in krita has access to some of the classes in Krita (those you can directly access from C++ Krita class), and you call them as if those were python classes.

Ad1
According to this tutorial (part1) in 11:38 you can see, that you only get the filter to the variable. Then you have to apply it with parameters, and refresh the whole document to see the difference

f = Krita.instance().filter('invert')
f.apply(parameters for invert action)
Krita.instance().activeDocument().refreshProjection()

According to Filter class documentation, you will need to use InfoObject class to get the parameters of the given filter.

Ad2
You get it with:

[print([a.objectName(), a.text()]) for a in Krita.instance().actions()]

I recommend to save the output in a file and use ctrl+f(find) to get what you need.
I’ve noticed some issued when you try to apply more than one of those in one script, so I try to avoid using those actions - sometimes it’s possible using variables from the document() or node()
Ad3
I see no Selection method in Krita class (which you should always refer Krita.instance().). There is one in a document class (Krita.instance().activeDocument().selection()) that gives you a global selection that you can write to a variable (None if there isn’t one) .

activeDoc = Krita.instance().activeDocument()
currentSelection = activeDoc.selection()

To clear a selection without using Krita actions in my script I used

activeDoc = Krita.instance().activeDocument()
activeDoc.setSelection(None)

you can also create a new selection and set it to active document

s = Selection()
activeDoc.setSelection(s)

1 Like