beginner lesson 13

Resources

Learn how to work with resources like patterns, brushes, and gradients

What are resources?

Resources are various files that come bundled with Krita. These are some types of resources that come with Krita. Things like external brush packs and "bundles" are adding additional resources.

  • Brush presets - The configuration of how a brush will behave. Referred to with a few names: brush preset, paintoppreset, or brushes
  • Brush image tips - Used in brushes that need a texture
  • Patterns - Auto-tiling images that can be used as fills or assigned to a brush
  • Gradients - Color and position data with how gradients will work
  • Workspaces - The arrangement and visibility of dockers and the application layout
  • Color palettes - Sets of color swatches
  • SVG Libraries - Sets of vector objects
  • Gamut masks - Shapes that mask out the color wheel. Used for creating color harmonies
  • Window layouts - How the application UI is managed when on multiple monitors
  • Layer styles - Configurations of layer styles that achieve certain effects
  • Sessions - Configurations that store the windows and images opened. Think of it like how you would restore a session if a program crashed, and you wanted to get back to where you were with your image(s) open and all.
  • Task sets - A set of actions that are recorded and replayed. There is a task set docker where these are created and used.

How did I find all these available resource types? In the application main menu go to Settings > Explore Resources Cache Database. Go to the resources tab in this window. In here there will be a resource type field where you can see the ID.

Resource database viewer

Accessing resources

If you want to grab what is available for a type of resource you can do it through the Resources API. You cannot grab everything at once, but have to grab resources by type first like this.

# working resources
print(Krita.instance().resources('brush')) # brush image tips
print(Krita.instance().resources('gradient'))
print(Krita.instance().resources('pattern'))
print(Krita.instance().resources('workspace'))
print(Krita.instance().resources('preset')) # brush preset
print(Krita.instance().resources('palette')) # color palettes

# not working right now (could also be spelled wrong)
print(Krita.instance().resources('gamutmasks'))
print(Krita.instance().resources('svgsymbols'))
print(Krita.instance().resources('windowLayouts'))
print(Krita.instance().resources('layerstyles'))
print(Krita.instance().resources('sessions'))
print(Krita.instance().resources('tasksets'))

Note that some of these currently are not working, but they should hopefully be working by the time Krita 5.0 comes out. This is because Krita 5.0 is re-writing how resources are managed. This is what is causing some resource types to be in a broken state at the moment.

Working with resources

Resources are all have a similar format. They are mostly file references with a bit of metadata attached to them. They really cannot do much by themselves. Other API calls require resource objects, though, so we need to understand how to grab them. Now that we do, let' work with a brush preset a bit and change some properties.

# get all brush presets
# this returns a python dictionary
allBrushPresets = Krita.instance().resources('preset')

# get brush we want to do stuff with
# I found this by looking at the following output... 
# print( '
'.join(list(Krita.instance().resources('preset').keys())) )
brushPreset = allBrushPresets['b) Basic-1']

# setting the brush as the current preset allows
# us to make other changes later
currentView = Krita.instance().activeWindow().activeView()
currentView.setCurrentBrushPreset(brushPreset)

# now we can change the current brush's properties
currentView.setBrushSize(34) # in pixels
currentView.setPaintingOpacity(0.3) # 0-1
currentView.setPaintingFlow(1.0) # 0-1

This changes a few properties on the selected brush. Most of the settings for a brush preset cannot be changed through the API currently. You only have these limited options.

Limited use of resources currently

There really isn't much you can do with resources right now if you are really wanting full control. The Krita View API Class in the Krita library is where you can set active resources, but there isn't a lot else beside that. If there are additional things you would like to do, make sure to put in a feature request, or ask for help on the Krita artist forum.

Have questions, need help, or find a typo?

Head to the Krita artists where we have a dedicated area for plugin development and give any feedback you might have.

;