I had this problem in my custom script in PyQGIS.

I create the variable as input in this way:

##lista_formaciones_forestales_con_estrategia = file

In theory this is the correct way to write a non-optional parameter as input, but when I open my script it is writing as optional:

enter image description here

Is it a problem with my QGIS version? My QGIS version is 2.16.1.

  • 2
    It doesn't seem to be your QGIS version. I've tried with v2.14.8 and 2.18 with no luck. I faced the same issue last time and decided to validate the input parameter by myself in the script code. See highlighted lines in this script to get an idea. – Germán Carrillo Oct 25 '16 at 21:02

I'm not sure but the default parameter setting for both File and Folder are set to True in some recent versions of QGIS (not sure which ones exactly but I used QGIS 2.16.1). You can see this setting from the GitHub script [line 503]:

def __init__(self, name='', description='', isFolder=False, optional=True, ext=None):

What we can do is change




You can find this script in your processing directory. For example, in my QGIS 2.16.1 standalone version, the script resides in:

C:/Program Files/QGIS 2.16.1/apps/qgis/python/plugins/processing/core/parameters.py

Then search for class ParameterFile(Parameter) to see the function as shown in the link above and change the boolean value. The File and Folder parameters should now be required by default. And if you want to make it optional, use the same method as before (e.g. ##lista_formaciones_forestales_con_estrategia=optional file).

(Note: You may have to move the "parameters.py" file outside the folder, edit and save the file, then insert it back to the same folder.)

  • Thanks for your answer Joseph, but it doesn't work me, :) – corting Nov 2 '16 at 11:09
  • @corting - Interesting, were you able to edit the parameters.py file? Hopefully Germán Carrillo's solution would help ;) – Joseph Nov 7 '16 at 10:23

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.