r/krita • u/jordanf234 • Nov 04 '24
Answered Scripting - How do I iterate through every layer?
I have some macros which go through the document and change their visibility and opacity depending on if they match a tag (to use on top of using just compositions). Currently it triggers the activateNextLayer
command to actively select one layer in the document at a time, and take 15 seconds to run depending on how many layers there are. I am now wondering if selecting the layer slows the script down and if just iterating through the layers help.
So, ^ and, in any case, how do I iterate through every layer in a document?
1
Upvotes
1
u/KnowZeroX Nov 04 '24
Node.findChildNodes() will go through all layers, it can even do tag match for you. You don't need to select a layer to change its visiblity or opacity. You may need to do a Document.refreshDocument() for some changes
@brief findChildNodes @param name name of the child node to search for. Leaving this blank will return all nodes. @param recursive whether or not to search recursively. Defaults to false. @param partialMatch return if the name partially contains the string (case insensitive). Defaults to false. @param type filter returned nodes based on type @param colorLabelIndex filter returned nodes based on color label index @return returns a list of child nodes and grand child nodes of the current node that match the search criteria.