How to change layer property (etc)?

I have an idea of a simple action:

  1. Create a new Fill Layer with neutral grey, and set the opacity to 50%
  2. Create a new normal blank layer

This way one can easily draw something new using whatever is on the canvas as reference (for example, inking a sketch).

In Photoshop we can just use a macro… but it seems that Krita doesn’t even have macro? Do I have to make a Python plugin? If so, how to create such a Fill Layer in Python?

I looked this up in the manual for you. Here’s what I found:

Macros

Deprecated since version 3.0: Macro recording and playing is disabled since 3.0 due to unmaintained code and buggy behaviour leading to crash.
Tools Menu — Krita Manual 5.2.0 documentation

There is something called Task Sets Docker you can play around with. I haven’t tried it myself so I don’t know if it will do exactly what you want.

Do you need that from time to time while painting something, or do you want this from the outset / from the beginning for a project?
If the latter, then you can create a template which you can call to begin a new project with.
On the other hand, you can use such a template anyway and use it for every project you begin. And if you don’t need that layer in a project, you can disable it after creation.

Michelist

A lightweight solution to add a macro-like feature is to create a Python script and add it to Ten Scripts plugin, which is available in Krita by default (not on Android).

You can then customize a shortcut for the script slot you used in Krita settings.

Ideally I want to bind it to a shortcut so I can invoke it whenever needed.

I checked Task Sets, but I don’t think it’s possible to implement this as a Task Set.

Then you will have to go @YRH’s way, this should be the fastest way to get something like that, I guess. If you can do it yourself or if a developer is needed to create it, I don’t know, but what I know is, that it is far beyond my abilities.

Michelist

And here is a little script that can be run in Krita’s Scripter and / or added to Ten Scripts plugin.

Script will add gray half transparent layer and paint layer, above currently selected layer. Order of layers can be swapped by commenting (comment is everything at line after # char) lines below option A / B

import random
from krita import Krita, InfoObject, Selection


def get_random_suffix():
    return ''.join(random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for _ in range(5))


def create_overlay():
    app = Krita.instance()
    doc = app.activeDocument()
    if not doc:
        return  # no doc
    node = doc.activeNode()
    if not node:
        return  # no node
        
    info = InfoObject()
    info.setProperty(
            'color', (
                '<!DOCTYPE color>'
                '<color channeldepth="U16">'
                ' <RGB r="0.217624172568321" g="0.217624172568321" b="0.217624172568321" space="sRGB-elle-V2-g10.icc"/>'
                '</color>'
            ))

    selection = Selection()
    selection.select(0, 0, doc.width(), doc.height(), 255)
    
    suffix = get_random_suffix()

    fill_layer = doc.createFillLayer(f'fill_gray_half_transparent_{suffix}', 'color', info, selection)
    fill_layer.setOpacity(127)

    paint_layer = doc.createNode(f'new_paint_layer_{suffix}', 'paintlayer')
    
    parent_node = node.parentNode() or doc.rootNode()

    # option A order fill_layer, paint_layer
    parent_node.addChildNode(paint_layer, node)
    parent_node.addChildNode(fill_layer, paint_layer)

    # option B order paint_layer, fill_layer
    # parent_node.addChildNode(fill_layer, node)
    # parent_node.addChildNode(paint_layer, fill_layer)

    return fill_layer, paint_layer


create_overlay()

/AkiR

3 Likes

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