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 QGIS plugin that performs a long-running operation, eventually producing and loading new shapefiles into QGIS. (I have this as a plugin rather than just a function that can be called from the console because the console doesn't work very well for long-running operations.)

Internally, the plugin creates a complex Python data structure. I would like a user to be able to access this data structure from the QGIS Python console.

I know that this could be done by serializing the data structure to a file and then loading it from a file (slightly more difficult in this case because the data structure cannot be pickled) but I am wondering if there is some sort of global variable inside QGIS to which I can assign my data structure from the plugin so that it can be directly used from the Python console.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You are able to access any plugin data by using the qgis.utils.plugins

from qgis import utils
mypluginInstance = utils.plugins['myplugin']
print( mypluginInstance.myData )
share|improve this answer
    
Thanks for this. You can use the same lines to create a reference and access functions from a plugin too. Without this answer I may never have known how. ie mypluginInstance.mypluginfunction() –  Mr Purple Apr 25 at 11:50

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.