After a few comments and my own consideration I've completely Edited the content (and title) of this post.

What are valid "output_layer" parameter options when scripting with the "saveselectedfeatures" tool?

I'm writing a script that uses the tool as follows:

processing.runandload('qgis:saveselectedfeatures', Input, 'Output.shp')

I also tried removing the shapefile extension and just putting 'Output' as the final parameter. Still errors and no resulting output.

Don't worry about "Input", it's a perfectly valid layer with selected features.


@Joseph provided the partial solution of replacing " 'Output.shp' " with " None " (no quotations).

processing.runandload('qgis:saveselectedfeatures', Input, None)

This results in successful execution with a temporary output layer called "Solution" popping up in the Layers Window.


I call this a partial solution because I find it hard to believe that the designer(s) of this tool didn't also intend to give users the option to choose the name of their output file (as I originally tried to do) via the final parameter ('output_layer'), as described in the tool's Help Tab.


The tool's Help tab offers the following instruction:

enter image description here

enter image description here

But it seems this is not quite as "helpful" as it could be. It seems like a few short and simple examples of acceptable values for the 2nd parameter would avoid any confusion.

Something like:

Output file options:  temporary layer, Shapefile, etc...

2nd Parameter ('output_layer') options:  
" 'User_chosen_name' " (or " 'User_chosen_name.shp' "), OR "None" (produces auto-named temporary layer). 

I'm a relatively new user of QGIS.

  • As an FYI, you can replace runalg with runandload to load the output shapefile into QGIS.
    – Joseph
    Oct 30, 2015 at 10:37
  • @user3309182 - Most welcome buddy :)
    – Joseph
    Oct 30, 2015 at 11:49
  • Thanks @Joseph. A great tip to know! I'm using "runandload" now but nothing is loading. Obviously something is still wrong with one of my two parameters.
    – Waterman
    Oct 30, 2015 at 11:51
  • @user3309182 - Could you edit your question please to include your script so that potential answerers have a better chance of helping you? :)
    – Joseph
    Oct 30, 2015 at 11:58
  • @Joseph - Complete code now added but figured that would be distracting to the question since I'm quite confident it has no bearing on why "saveselectedfeatures" is failing. Reasoning: I know the first parameter is fine since "Input" is understood by another tool in my script. That leaves just the 2nd parameter where I figure the problem must be. Does that make sense?
    – Waterman
    Oct 30, 2015 at 12:03

1 Answer 1


Turns out (on a Mac at least) you have to put the full path plus the name for your file. For example, the following code places the output shapefile "MyFile" on my desktop.

path = "/Users/User1/Desktop/"
processing.runandload('qgis:saveselectedfeatures', Input, path+'MyFile.shp')

Seems obvious in hindsight but again better documentation in the Help tab would have been a simple way to avoid confusion.

Still need to figure out why the output gets loaded onto map project as "Selection" and not with the name I provided ("MyFile"), but I've already asked that question in another post ("How to write QGIS script to load Output file to Map Project with Desired Name?")

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.