8

I am trying to launch the UI of a processing algorithm using Python script but I cannot find a simple way for it (aside double clicking on it in the process toolbox of course). The plugin is a water network simulator and I just want to launch its pre-processing UI without using process.runalg() because this needs to enter arguments and I don't need it.

Some ways would be to trigger processes available in process toolbox or sending command to commander from python console. but I have no clue how and I am searching for 2 hours now, no results.

1
  • 1
    Hi, thanks again for the answer.. Although I was doing PyQGIS exclusively for my thesis so I passed this stage and didn't have it anymore until now I tested it in some other PCs. but thanks any ways :) Jan 24, 2016 at 17:35

2 Answers 2

11

You can do that from the QGIS Python console in this way:

# Import both Processing and CommanderWindow 
#   classes from the Processing framework. 
from processing.core.Processing import Processing
from processing.gui.CommanderWindow import CommanderWindow

# Then get the algorithm you're interested in (for instance, Join Attributes):
alg = Processing.getAlgorithm("qgis:joinattributestable")

# Instantiate the commander window and open the algorithm's interface 
cw = CommanderWindow(iface.mainWindow(), iface.mapCanvas())
if alg is not None:
    cw.runAlgorithm(alg)

That's it! You get the algorithm's UI open.

enter image description here

Note: You can get the names of the available algorithms by entering these lines in the QGIS Python console:

import processing
processing.alglist()

Tested in QGIS 2.10.1, Processing framework v.2.9.1 and v.2.10.1


EDIT:

If you find errors when running the code snippet above, chances are you're using QGIS v2.16.0, v2.16.1, or v2.16.2. To solve the issue, install QGIS v2.16.3.

2
  • 1
    tested also for the upcoming QGIS3, thanks!
    – matteo
    Mar 14, 2017 at 15:31
  • 1
    Hmm, in QGIS 3.4.1 I can't import CommanderWindow.. Any idea how to fire up a Processing GUI in the current API?
    – nnolde
    Dec 24, 2018 at 21:43
2

To open a processing algorithm GUI on QGIS 3.x series, you need to do the following:

import processing
processing.execAlgorithmDialog('native:buffer')
# Can take parameters to prefill the GUI fields
processing.execAlgorithmDialog('native:buffer', parameters= {'INPUT':iface.activeLayer(),'DISTANCE':10,'SEGMENTS':5,'END_CAP_STYLE':0,'JOIN_STYLE':0,'MITER_LIMIT':2,'DISSOLVE':False,'OUTPUT':'TEMPORARY_OUTPUT'})

You can get list of algorithms identifier and associated name with

for alg in QgsApplication.processingRegistry().algorithms():
        print(alg.id(), "->", alg.displayName())

Code above is an excerpt from official doc "Using processing algorithms from the console"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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