I've recently started working with Python in QGIS and I've been trying to make a script that dissolves a polygon layer and saves the output in the same folder as the input, something I believe isn't possible to do with QGIS Graphical Modeller.
The code I've written is as follows:
processing.run("native:dissolve", {'INPUT':iface.activeLayer(),'FIELD':[],'OUTPUT':iface.activeLayer().dataProvider().dataSourceUri().split('2D', 2)[0] +"2D Simulation Elements dissolved.shp"})
iface.addVectorLayer((iface.activeLayer().dataProvider().dataSourceUri().split('2D', 2)[0] +"2D Simulation Elements dissolved.shp"),"","ogr")
It works fine in the console, however when I put it in the Script Toolbox it fails with the following error:
The code is confusing me cause, I obviously don't have 224 lines of code for it have an error there... I've looked online and followed the suggestion to add the following on top of my code:
QgsApplication.initQgis()
app = QgsApplication([], True)
But it didn't make my script work as well.
from qgis.core import QgsApplication