I have an expression tag that runs a script (getTrendList()
) via runScript()
.
This is the script:
def getAllTrendPens():
data = system.db.runNamedQuery("getHistoryTags")
if data is not None:
historyTagPaths = data.getColumnAsList(0)
trendLabelPaths = [historyTag+".Trend_Label" for historyTag in historyTagPaths]
trendLabels_qv = system.tag.readBlocking(trendLabelPaths)
trendLabels = [label.value for label in trendLabels_qv]
colors = ["#66FFFF","#B266FF","#FF3333", "#66FF66", "#000099", "#FF66B2", "#CCCC00", "#000000", "#606060" ]
pens = []
for i, pen in enumerate(trendLabels):
if pen is not None:
color = colors[i % len(colors)]
#print pen
#print historyTagPaths[i]
jsonObject = {
"name": pen,
"visible": False,
"enabled": True,
"selectable": True,
"axis": "",
"plot": 0,
"display": {
"type": "line",
"interpolation": "curveLinear",
"breakLine": True,
"radius": 3,
"styles": {
"normal": {
"stroke": {
"color": color,
"width": 1,
"opacity": 0.8,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 0.8
}
},
"highlighted": {
"stroke": {
"color": color,
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 1
}
},
"selected": {
"stroke": {
"color": color,
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 1
}
},
"muted": {
"stroke": {
"color": color,
"width": 1,
"opacity": 0.4,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 0.4
}
}
}
},
"data": {
"source": "histprov:MSSQLSERVER1:/drv:ignition-scada-pc:default:/tag:"+historyTagPaths[i],
"aggregateMode": "default"
}
}
pens.append(jsonObject)
return pens
def getTrendList():
headers = ["Name", "Pen"]
pens = trendPens.getAllTrendPens()
names = [pen["name"] for pen in pens]
data = [[name,pen] for name, pen in zip(names, pens)]
dataset = system.dataset.toDataSet(headers, data)
return dataset
When I call trendPens.getTrendList()
from the script console it returns a dataset, but when called from the expression I get a type conversion error.
Error_TypeConversion("class org.python.core.PyDictionary: Invalid DataType for Dataset.")