How to use FileLayer?

Hello,

My purpose is to add file layers into my document, linking to existing other documents.

However I can’t figure out how to use FileLayer (if this is possible) in python scripts. I’d like to have access to its methods so I can set its properties after creating it (with FileLayer.setProperties() from libkis documentation).

            root = doc.rootNode()
            layer = doc.createNode(name, "filelayer")

            print("layer has path() method ? " + str(hasattr(layer.__class__, "path")) ) # doesn't have FileLayer methods such as FileLayer.path()

How can I achieve this ?

Thanks :+1:

There is a createFileLayer method in Document, so you can automatically set the properties.

Also, there is a recent thread talking about doing similar to what you want:

1 Like

Welcome to my hell Elis haha

this is what I’ve got so far - but I’m still having trouble with it.

doc = Krita.instance().activeDocument()
name = “test”
fileName = “C:\test.exr”
scalingMethod = “none”
createFileLayer = doc.createFileLayer(name, fileName, scalingMethod)
root = doc.rootNode()
root.addChildNode(createFileLayer, None)

KnowZero has been helping me along the way and has been a great help.But man oh man has this been frustrating for me haha

Learning tons though!

If you see something I’m missing LET ME KNOW!

1 Like

GOT IT!

I had to input a double \ in the fileName parameter and it worked!

doc = Krita.instance().activeDocument()
name = “test”
fileName = “C:\test.exr”
scalingMethod = “none”
createFileLayer = doc.createFileLayer(name, fileName, scalingMethod)
root = doc.rootNode()
root.addChildNode(createFileLayer, None)

Thank you KnowZero for all your help!

1 Like

Thanks to both of you !
I wasn’t aware of this createFileLayer method in Document, it was the key :ok_hand:

1 Like

If you haven’t yet, check out the Python Plugin Developer tools. There is a full list of Krita API plus other tools that make making python scripts and plugins much easier.

2 Likes

I second this. It proved to be invaluable. I can’t recommend this plugin enough