How to delete all empty layers?

Maybe this needs a script…

1 Like

Yes I am interested in this too.

1 Like

I currently use Ctrl+T to detect empty layers, because it’ll say you can’t transform the layer if it’s empty. Not the best

1 Like

Hi,

Really basic script

from krita import *

def recursiveCleanup(node):
    for childNode in list(node.childNodes()):
        if childNode.type() == 'grouplayer':
            recursiveCleanup(childNode)
            
            if len(childNode.childNodes()) == 0:
                print(f"Remove empty {childNode.type()}: {childNode.name()}")
                node.removeChildNode(childNode)
        else: # if childNode.type() == 'paintlayer':
            if not childNode.hasExtents():
                print(f"Remove empty {childNode.type()}: {childNode.name()}")
                node.removeChildNode(childNode)
    

doc = Krita.instance().activeDocument()
if doc is not None:
    recursiveCleanup(doc.rootNode())

Should work properly for paint layers & group layer, but might need some improvements to manage case of filter mask & co.

edit: ensure there’s an active document :slight_smile:

Grum999

3 Likes

Thank you for your answer! It can now delete redundant paintlayers, vectorlayers and group layers with one click!

Ps: Strangely, when vector layer, clone layer and gruop are selected, I cannot execute the script, and the buttons are gray
image

Is it 10 script?
If yes I think that’s a limitation of plugin, to restrict execution in some condition only… :thinking:

If you execute code from scripter, does it work in this case?

Grum999

Yes, it works.

It is not available on clone layer, file layer, vector layer, group layer and transform mask.

I think its judging condition is whether the layer has editable pixels.

Ideally, 10 scripts shouldn’t judge if a script is executable or not as some script may not be related to layer management…

I can’t do anything here, at least open a bug on bugs.kde.org to ask to remove current restriction: that’s the role of a script to ensure in which condition it could be executed, not the plugin…

Grum999

1 Like

459495 – Remove layer restrictions for “ten scripts” (kde.org)

3 Likes

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