Have more control with your images by selecting specific parts to affect.
Some operations you only want to do on specific parts of an image. Whether it is copying it to a new layer, or performing a filter. The selections API allows you to have control over the selections you make. The following example adds a rectangle selection.
You can also start moving and doing other operations to selections once you have one. Here is a script that is using a bit of the Selections API to modify and remove the existing one.
One thing that can be confusing is that many of these operations are also available with actions. If you look through the action dictionary, you will see you could also use that. There are certain situations where using actions can be easier to work with.
One area that can cause confusion is copying and pasting selections. The actual paste API call is a bit buggy, so it is a bit easier to just use the action for this situation. Here is an example of how to set that up.
When we call the edit_paste action, notice how there is a waitForDone() method. With actions and some image operations, that needs to be called, otherwise you might get inconsistent results. With the edit_paste action, it does a few things like create a new layer, paste the selection to the new layer, and updates the current selected layer. We want all that to be finished before we continue.
If you want to read more about the various things you can do, check out the Selections API page that lists all the methods that are available.
Head to the Krita artists where we have a dedicated area for plugin development and give any feedback you might have.