Luca Brasi wrote:Ok, here I am not entirely sure if I understand you correctly because in my example above the problem was that eg.result was not changed when doing an action inside the script.
ok here goes another attempt at explaining this. since i made a mess of the last one!
from the code I read if you call the action directly eg.plugins.SOME_PLUGIN.SOME_ACTION() it will only return the value. eg.result will only get set if an action gets run from it's GUI form.
**** more information on eg.result and python scripts ****
here is a code block from the python script plugin. self.mod is the storage for any local variables. local variables are variables only accessible by the script.
Code: Select all
mod = self.mod
oldResult = eg.result
mod.result = oldResult
try:
exec(self.code, mod.__dict__) # pylint: disable-msg=W0122
except SystemExit:
pass
except:
self.PrintTraceback()
if eg.result is not oldResult:
return eg.result
else:
return mod.result
so what is taking place here is eg.result gets set into the result variable of your script. so while the script is running you can access eg.result as just result inside of your script. if you want to return a value from your script (which will then get set as eg.result) simply set whatever data is to be returned from the script into the result variable.
Code: Select all
result = 'this is what i want returned from the script'
****some more info that might be useful****
now here is a real brain spinner for ya. i believe you can do this because the variables are stored in a dict which is mutable and will carry the variable names and values between running instances. I have not tested this but from the code it looks like this can be done.
Code: Select all
try:
print 'This script has been run %d times.' % run_count
run_count += 1
except:
print 'This is the first time this script has run.'
run_count = 1