How do I export my processing modeler as .py so that I can edit its code?
This does not seem as intuitive as previous versions.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Early versions of QGIS 3 did not support exporting models to scripts (See: Why "Export as Python script" button is unaccessible in QGIS 3.0/3.1 Modeler by default?)
From QGIS 3.6, the export to script button is back and creates a proper QGIS3 Processing script:
You can make it accessible.
"ModelerDialog.py"files in QGIS folder. (That folder depends on which way you installed it).
"DlgModeler.ui"is located in "QGIS_PATH/python/plugins/processing/ui/" and
"ModelerDialog.py"is located in "QGIS_PATH/python/plugins/processing/modeler/"
"DlgModeler.ui"in editor (maybe notepad), find "addaction" tags. Add
"<addaction name="mActionExportPython"/>and save.
"ModelerDialog.py"in editor and uncomment the lines below and save it.
EDIT: As @ndawson says (in comments), this method just re-adds the removed "Export as Python Script" button. Exported script has QGIS 2.x syntax and it won't be usable in QGIS 3.x. For further information about QGIS 3.x syntax, visit Processing script template for QGIS3.
EDIT2: From v3.6, QGIS supports to export a model as Python script. Look at @underdark's answer.