7

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/15726 – Jesse McMillan Oct 23 '16 at 6:31
  • Could you make a workaround based on catching the QgsComposerMap.preparedForAtlas() signal? – Vincent_v_E Nov 3 '16 at 15:33
  • Thanks for your suggestion. I don't know how to do that but I will research. – Jesse McMillan Nov 3 '16 at 22:39
  • @JesseMcMillan Please post the feature request as an answer. – underdark Dec 4 '17 at 18:34
0

Not currently possible. Feature request here: https://issues.qgis.org/issues/15726

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.