Krita illustration software

Hiding multiple layers

From a blog post from 2019-08-01

When working on my comic, I create a bunch of layers named Pencils where I do my cleaner pencil drawings overtop of my layouts, usually one layer per character or important prop. When I've finished inking (in another layer for each object) overtop of the Pencils layers, I hide all the Pencils layers. These can be nested pretty deep, and there can be a lot of them, and I've been wanting to expand my Python knowledge a bit, so here's a little script (copypaste into the Scripter plugin editor pane) to turn them all off:

snippet.python
from krita import *
 
active = Krita.instance().activeDocument()
queue = [active.rootNode()]
 
while len(queue) > 0:
  node = queue.pop()
  if node:
    if node.name() == "Pencils":
      node.setVisible(False)
    for child in node.childNodes():
      queue.append(child)
 
active.refreshProjection()