1

I am trying to learn how to use macros in QGIS. As a first task, I would like to display a message whenever I save a project. That is to say, I would like to have this code executed:

from qgis.utils import iface
iface.messageBar().pushMessage("Info","PushMessageTest")

I tested this code in the Python Console, it works: enter image description here

First, I macros them via Settings -> Options..., then change the Enable macros field to Always (Not Recommended): enter image description here

Then, I edit the saveProject function within Project -> Properties... -> Macros so that it contains the to be executed code. (I also make sure that the Python Macros tickbox above the function definitions is ticked.) enter image description here

Yet, whenever I click on the save project icon (top left): enter image description here or press Command-S, the project is saved, but the message PushMessageTest does not show up.

I would like to know what I am doing wrong.

Why does the saveProject macro fail to execute?

1 Answer 1

0

Restarting QGIS solved the problem: I need to edit the macro, then the message does indeed show up upon saving a project.

Ideally, it would be better not having to do this, but this works.

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.