File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
python/plugins/processing/script Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 5454from processing .core .outputs import OutputFile
5555from processing .core .outputs import OutputDirectory
5656from processing .core .outputs import getOutputFromString
57+ from processing .core .ProcessingLog import ProcessingLog
5758from processing .script .WrongScriptException import WrongScriptException
5859from processing .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
5960
@@ -321,16 +322,19 @@ def processAlgorithm(self, progress):
321322 ns [out .name ] = out .value
322323
323324 variables = re .findall ("@[a-zA-Z0-9_]*" , self .script )
324- print variables
325325 script = 'import processing\n '
326326 script += self .script
327327
328- scope = QgsExpressionContextUtils .projectScope ()
328+ projectScope = QgsExpressionContextUtils .projectScope ()
329+ globalScope = QgsExpressionContextUtils .globalScope ()
329330 for var in variables :
330331 varname = var [1 :]
331- if not scope .hasVariable (varname ):
332- raise GeoAlgorithmExecutionException ("Wrong variable: %s" % varname )
333- script = script .replace (var , scope .variable (varname ))
332+ if projectScope .hasVariable (varname ):
333+ script = script .replace (var , projectScope .variable (varname ))
334+ elif globalScope .hasVariable (varname ):
335+ script = script .replace (var , globalScope .variable (varname ))
336+ else :
337+ ProcessingLog .addToLog (ProcessingLog .LOG_WARNING , "Cannot find variable: %s" % varname )
334338
335339 exec ((script ), ns )
336340 for out in self .outputs :
You can’t perform that action at this time.
0 commit comments