10

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.

Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Aug 13, 2013 at 16:41

1 Answer 1

13

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)
Taras
35.7k5 gold badges77 silver badges151 bronze badges
answered Aug 13, 2013 at 17:48
1
  • 2
    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() Commented Apr 25, 2014 at 11:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.