I'm looking for a way to execute a python script upon exporting a print composer. Specifically, I want it to run once for each page exported. (logging some data and possibly updating a database).
So far I've created a custom expression that writes a log to a file and returns an empty string. I created an off-page label that runs the expression.
The problem is, this runs every time the page refreshes so it's running a bunch just paging through the atlas.
Trying to get it to run only on export, I put it in the 'export filename' field but that too runs every time the page refreshes.
Is there some way I can either force it to only run on export, or in the python code detect if the page is being exported before running?
edit: here's the test code I'm running so far:
def logTest(logitem):
global logFileName
f = open(logFileName, 'a')
f.write("{}\n".format(logitem))
f.close()
@qgsfunction(args='auto', group='Territory')
def postData(postItem, feature, parent):
logTest(str(postItem))
return u''
and my expression to test it is simply:
postData("id")
-
Doesn't seem possible. Created a feature request here: hub.qgis.org/issues/15726user52245– user522452016年10月23日 06:31:19 +00:00Commented Oct 23, 2016 at 6:31
-
Could you make a workaround based on catching the QgsComposerMap.preparedForAtlas() signal?Vincent_v_E– Vincent_v_E2016年11月03日 15:33:12 +00:00Commented Nov 3, 2016 at 15:33
-
Thanks for your suggestion. I don't know how to do that but I will research.user52245– user522452016年11月03日 22:39:38 +00:00Commented Nov 3, 2016 at 22:39
-
@JesseMcMillan Please post the feature request as an answer.underdark– underdark2017年12月04日 18:34:42 +00:00Commented Dec 4, 2017 at 18:34
1 Answer 1
Not currently possible. Feature request here: https://issues.qgis.org/issues/15726