Hi,

I am trying to implement a Python action in "form" and "feature" action scope that uses a QGIS expression, but fail to get a valid expression calculation.

Here is my code so far:

from qgis.PyQt.QtWidgets import *
from qgis.core import QgsMessageLog

expContext = QgsExpressionContext()
expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))
expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))

exp = QgsExpression('t_id')

expResult = exp.evaluate(expContext)
QgsMessageLog.logMessage('Expression Result=' + str(expResult))

So even the most basic expression (getting a field value) will not work in my code. I always get "None" as a result.

Any idea what is missing? Am I missing a certain scope or an import statement?

Thank you very much for any hints what might be wrong here ...

Andreas
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to