In QGIS I would like to create an action of type "python" on layer scope, aim of this simple action is to print out the selected feature of the layer the action is defined on:

enter image description here

My simple question is: How do I refer to the layer the action is defined on in the python code?

1 Answer 1


I have used this approach in Python actions previously to get a reference to a QgsMapLayer object and it works well:

layer_id = '[%@layer_id%]'
layer = QgsProject().instance().mapLayer(layer_id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.