Hi Everyone,
I am new to the community, and I was hoping to get some help on a script I am writing. I would like to specify which Easy Chart pens are enabled when a window opens. I am not sure if I can do this with an Ignition dataset or a PyDataset. Any help would be very much appreciated. Thanks!
Basically, I am trying to loop through the dataset and look for specific pen names. I will then try to set the “ENABLED” value accordingly.
logger = system.util.getLogger(‘myLogger’)
logger.info(“Starting Script…”)
window = system.gui.getParentWindow(event)
rootCont = window.getComponentForPath(‘Root Container’)
chart = rootCont.getComponent(‘Easy Chart’)
data = chart.tagPens
headers = system.dataset.getColumnHeaders(data)
rows = []
for row in range(data.rowCount):
name = data.getValueAt(row, “NAME”)
if str(name) == "SV9001":
pensDisabled = system.dataset.setValue(data, row, "ENABLED", 0)
rows.append(pensDisabled)
print "here is one %s" % name
else:
pensEnabled = system.dataset.setValue(data, row, "ENABLED", 1)
rows.append(pensEnabled)
print rows
ds = system.dataset.toDataSet(headers, rows)
event.source.parent.getComponent(‘Easy Chart’).tagPens = ds
I forgot to mention that when I run this code, I get the following exception:
15:20:07.722 [AWT-EventQueue-0] ERROR com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter - Error executing script for event: actionPerformed
on component: Button
.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
File “event:actionPerformed”, line 29, in
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:326)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to org.python.core.PySequence