How do I export my model from Processing Modeler as
.py so that I can edit its code?
This does not seem as intuitive as in previous QGIS 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).
By default (in Windows):
"DlgModeler.ui" is located in "QGIS_PATH/python/plugins/processing/ui/"
"ModelerDialog.py" is located in "QGIS_PATH/python/plugins/processing/modeler/"
additionally you may check this folder "C:/.../QGIS/apps/qgis-ltr/python/plugins/processing"
"DlgModeler.ui" in editor (maybe Notepad), find "addaction" tags.
"<addaction name="mActionExportPython"/> and Save.
"ModelerDialog.py" in editor and uncomment the lines below and Save it.
#self.mActionExportPython.setIcon( # QgsApplication.getThemeIcon('/mActionSaveAsPython.svg')) ... #self.mActionExportPython.triggered.connect(self.exportAsPython)
Open QGIS 3.0