I'd like to change the value of a user-defined project variable (can be manually edited in Project Settings | Variables) using the Python console. I tracked down the setVariable() function in the QgsExpressionContextScope class but haven't succeeded in actually changing the variable in the project settings. My code so far:
iface.mapCanvas().mapSettings().expressionContext().scope(0).setVariable('myvar',1)
I guess I'm getting lost in the different expression contexts ...
QgsExpressionContextUtils– ismailsunni Jul 24 '17 at 15:39setProjectVariables(preserved_variables)I have checked the C++ code, I hope I can contribute for the functionality. – ismailsunni Jul 25 '17 at 02:06QgsExpressionContextUtils.removeProjectVariableexists now! – letmaik Jan 20 '18 at 23:21