This one has me a little stumped. I’m writing a project script function and I want to send a list as one of the parameters. However, I get a CastException error.
I’m currently executing this in the script console. Ignition Version is 8.1.14
<type 'list'>
Java Traceback:
Traceback (most recent call last):
File "<input>", line 42, in <module>
File "<module:Orestes.Daily_DT>", line 27, in getDailyDT_CountsData
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1493)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:130)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:104)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:40)
at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.queryTagCalculations(AbstractTagUtilities.java:681)
at jdk.internal.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value 'set(['HalfSpdWhse4', 'NoTomatoes', 'Cooker', 'NoCans', 'Seamer', 'Depal', 'CleanMode', 'HalfSpdLowTom', 'NoMedia'])' into type: class org.python.core.PySequence
def getDailyDT_CountsData(paths,aliases,day):
startTime1 = system.date.setTime(day,6,30,0)
endTime1 = system.date.setTime(day,18,30,0)
endTime2 = system.date.addDays(startTime1,1)
daysData = system.tag.queryTagCalculations(paths,['Range'],startTime1,endTime1,aliases = aliases)
nightsData = system.tag.queryTagCalculations(paths,['Range'],endTime1,endTime2,aliases = aliases)
headers = ['DT-Event','Minutes-Days','Minutes-Nights','Counts-Days','Counts-Nights']
aliases = {alias.split('_')[0] for alias in aliases if alias not in ('CansTarget','CansAct')}
rows = [[alias,days[0][alias],nights[0][alias],days[1][alias],nights[1][alias]] for alias in aliases]
return system.dataset.toDataSet(headers,rows)
Where are you defining aliases before calling your project library script?
Your comprehension in the project lib is using a set (which isn’t going to respect ordering, probably not what you want) - are you using the same pattern when invoking the script?
aliases is defined in the same for loop where paths is defined.
paths = []
aliases = []
for k,v in tpml.iteritems():
paths.append(v)
aliases.append(k)
I will change that comprehension, I think the set was left over from a previous iteration, either way, the error occurs prior to that line in the script. I’m really only needing to remove the CansTarget and CansAct from the list, and there is a better way to accomplish that anyway.
In reality there are other helper functions which do this as well, they are defined in the same script library.
def getDailyDT_TagPathsList(lineNumber):
baseTagPath = 'baseTagPath/L{}'.format(lineNumber)
return [str(result['fullPath']) for result in system.tag.browse(baseTagPath + 'DT').results]
def getDailyDT_PathsDict(lineNumber):
baseTagPath = '[baseTagPath/L{}/'.format(lineNumber)
dtQueryPaths = ['Yearly_Minutes_Current','Yearly_Counts_Current']
tpl = getDailyDT_TagPathsList(lineNumber)
tpml = {path.split('/',-1)[-1] + '_' + qPath.split('_')[1]:path + '/' + qPath for qPath in dtQueryPaths for path in tpl}
tpml['CansAct'] = baseTagPath + '/EFF/CapperCounts_Yearly'
tpml['CansTarget'] = baseTagPath + '/EFF/TargetCansYearly'
paths, aliases = [],[]
for k,v in tpml.iteritems():
paths.append(v)
aliases.append(k)
return {'paths':paths,'aliases':aliases}
In practice getDailyDT_PathsDict() is used in a binding on a custom property, and then the ‘paths’ array and ‘aliases’ array are used in the call to getDailyDT_CountsData
getDailyDT_CountsData is intended to return a dataset to a table component on a perspective view.
What if you change line 27 like this? I wonder if the comprehension that’s re-using the same variable is leaking backwards, somehow? It’s hard to say without seeing everything in order to track the data flow (put it on the pile of issues that would be easy to solve with a debugger ).