[QGIS-Developer] passing parameters to QGIS Python-Script started via Command Line

Drexel Peter Peter.Drexel at vorarlberg.at
Mon Aug 8 06:47:32 PDT 2022


Hi everyone,
My goal: I want to open QGIS using the Command-Line, load a specific project, select specific features and zoom to the selected features.
What sounds rather difficult is actually mostly solvable using the following:
"C:\Program Files\QGIS 3.16\bin\qgis-ltr-bin.exe" -p "d:\standardebenen.qgs" --code myscript.py

This opens QGIS with the Project d:\standardebenen.qgs and after that it runs the script "myscript.py".
Within the scrip I can do everything what I can do in a Python-script, so there I can select some features in a layer and show that selection.
But this selections are "hard-coded" in the script, I cannot pass over these parameters to the myscript.py.
In "Pure Python" I can pass parameters to a Python Script using "python myscript.py arg1 arg2 arg3".
This seems to be not working in the QGIS-Command-Line  as the parameters are interpreted as "layers to load".
Am I right with my analysis?
One workaround is to write the parameters to al file and use this file within the myscript.py to define the selections. But this is very unhandy...
Are there any ideas from any QGIS-Expert to solve my problem?

If this cannot be solved in the current version of QGIS is one of the developers willing to get in contact with me to make an offer the implement this feature ?
Thanks
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220808/15b7bdbd/attachment-0001.htm>


More information about the QGIS-Developer mailing list