Setting Default Pens in Easy Chart when Opening a window

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

There’s a simpler way:

  1. Set up the EasyChart with the pens you wish to have present on startup, with the appropriate ones enabled and disabled. Then go to the “tagPens” property and open the dataset editor (next to the binding button). Use the button to copy the dataset to the clipboard.

  2. Create a custom dataset property in some convenient place – I usually use the root container. Open the dataset editor and paste the clipboard’s dataset.

  3. Go back to the EasyChart’s tagPens property and click the binding icon, and bind it to the custom dataset you just created.

Your chart will now start up with that set of pens every time, but allow runtime changes. If you are also using database pens or calculated pens, do the same with their configuration datasets.

1 Like

Excellent! This worked perfectly. Thank you very much.