4

Is there a way to start QGIS with custom command line arguments and to access those arguments at runtime in a plugin?

Background: I'm trying to start QGIS using a third party application(click on a GIS-Button, QGIS opens with a predefined project using the --project flag). After the project has finished loading I want to register a listener to a given layer inside that project. The name of the layer has to be passed somehow to QGIS. As the name may vary, my best guess was to append that somehow to the command line arguments. The intention of this process is to be able to perform selection, zoom and pan options in QGIS which are triggered by a third party application and, if the corresponding button is clicked, to send data (e.g. areas) back to the third party application for further use.

Basically I've got everything working except for the registering of the layer, which has to be done manually at the moment.

1 Answer 1

7

Passing extra parameters isn't possible as anything extra is considered a layer. However what you can do is pass the --code arg that can run a custom Python file to read arguments from somewhere e.g a file on disk.

Here is example of something like that:

myfile.txt:

custom layer name

loader.py:

layername = open("myfile.txt").read()
# Do some stuff with layername

qgis.exe --code loader.py myproject.qgs

Your Answer

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

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