Suppose a script has a variable number of outputs, which may or may not be produced depending on settings:
##Input_layer=vector
##Output_1=output vector
##Produce_output_2=boolean
##Output_2=output vector
from qgis.core import *
def create_my_output(path):
# whatever...
create_my_output(Output_1)
if Produce_output_2:
create_my_output(Output_2)
If this script is run with "Produce output 2" unchecked then QGIS displays a warning dialog saying Output 2 was not correctly produced, even though not producing Output 2 was clearly intended behaviour.
Is there a way to tell QGIS that an output is optional?
if Produce_output_2:
withif Produce_output_2 == True
? Then after yourcreate_my_output(Output_2)
, useelse: pass
.else: pass
do - isn't that effectively a null operation?if
statement though, it's generated by QGIS looking for an output that's not there if the conditional doesn't get run.