@@ -286,24 +286,39 @@ def runAlgorithm(algOrName, onFinish, *args):
286
286
if alg is None :
287
287
print 'Error: Algorithm not found\n '
288
288
return
289
- if len (args ) != alg .getVisibleParametersCount () \
290
- + alg .getVisibleOutputsCount ():
291
- print 'Error: Wrong number of parameters'
292
- processing .alghelp (algOrName )
293
- return
294
-
295
289
alg = alg .getCopy ()
296
- if isinstance (args , dict ):
297
- # Set params by name
298
- for (name , value ) in args .items ():
299
- if alg .getParameterFromName (name ).setValue (value ):
290
+
291
+ if len (args ) == 1 and isinstance (args [0 ], dict ):
292
+ # Set params by name and try to run the alg even if not all parameter values are provided,
293
+ # by using the default values instead.
294
+ setParams = []
295
+ for (name , value ) in args [0 ].items ():
296
+ param = alg .getParameterFromName (name )
297
+ if param and param .setValue (value ):
298
+ setParams .append (name )
300
299
continue
301
- if alg .getOutputFromName (name ).setValue (value ):
300
+ output = alg .getOutputFromName (name )
301
+ if output and output .setValue (value ):
302
302
continue
303
303
print 'Error: Wrong parameter value %s for parameter %s.' \
304
304
% (value , name )
305
+ ProcessingLog .addToLog (ProcessingLog .LOG_ERROR , "Error in %s. Wrong parameter value %s for parameter %s." \
306
+ % (alg .name , value , name ))
305
307
return
308
+ # fill any missing parameters with default values if allowed
309
+ for param in alg .parameters :
310
+ if param .name not in setParams :
311
+ if not param .setValue (None ):
312
+ print ("Error: Missing parameter value for parameter %s." % (param .name ))
313
+ ProcessingLog .addToLog (ProcessingLog .LOG_ERROR , "Error in %s. Missing parameter value for parameter %s." \
314
+ % (alg .name , param .name ))
315
+ return
306
316
else :
317
+ if len (args ) != alg .getVisibleParametersCount () \
318
+ + alg .getVisibleOutputsCount ():
319
+ print 'Error: Wrong number of parameters'
320
+ processing .alghelp (algOrName )
321
+ return
307
322
i = 0
308
323
for param in alg .parameters :
309
324
if not param .hidden :
0 commit comments