Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a .csv file containing financial data which is generated on a regular basis outside QGIS. Then I want to create a PyQGIS script that will add the .csv file as a layer in my project. (The idea here is I want to have the up-to-date financial data as attributes data for one of the shapefiles in the project). Is there a way to run the script automatically as soon as I open the QGIS project. Thank you

share|improve this question
    
Why not store the layer as a view in a database, and use your csv creation script to instead import the data to table as part of the view, the other part being the spatial component? –  wildintellect Mar 17 at 17:32

1 Answer 1

Put your script in .qgis/python/startup.py and it should run when QGIS is opened. However, this will run with any project you open, which you may not want.

So you might be better off setting up a python macro in the specific project. File > Project properties > Macros. Enable macrcos by checking the box.

def openProject():
    wack your code here!

def saveProject():
    pass

def closeProject():
    pass
share|improve this answer
1  
+1 Marcos are the way to go. If you have a lot of code I would suggest putting it in it's own .py file next to the project and importing it from openProject rather then putting lots of logic in the blocks. Makes it easier to test and debug. –  Nathan W Mar 17 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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