2

I just recently started to play with python and items in print composer. Given item ID it is possible to do many great things with the item through code, one of them is changing text of text label.

My template contain text label for date, coordinate reference system / projection and I would add project file path if possible to update it automatically.

Is it somehow possible to save python code within the template so whenever the template is loaded / exported it will update items like date / CRS / project file path?

  • 1
    Not sure but there are expressions you can insert for labels which will dynamically update such as now() for the date/time, @project_path for project path etc. – Joseph Aug 9 '16 at 10:47
  • 1
    Thank you @Joseph, I had no idea about this. I turned your comment into an answer if somebody miss that huge button the same way as I did. – Miro Aug 9 '16 at 12:07
  • Most welcome and don't worry, I missed that huge button once before ;) – Joseph Aug 9 '16 at 12:08
4

As Joseph suggested in comment for most of the things it should be sufficient to use expression (I have completely missed that option). I also had no idea it is possible to save that as part of template. Well it works great.

The button to insert expression:

enter image description here

For example if you like to have in the composer always current date (time) in the format of day/month/year the expression can be done as combination of now() and other functions:

[% day(now()) || '/' || month(now()) || '/' || year(now())%]

In the similar way for absolute project path:

[% @project_path %]

The only missing thing in my case is that I am not able to figure out now how to automatically display projection/CRS information. After clicking on Insert as expression there is second tab where it is possible to create and use custom function which should allow to display such information but as far as I am aware the custom function is not going to be saved with template and thus won't work if somebody use it on other device.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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