I have this script that creates a dataset. Runs fine in the script console with the same path provided, but I get an type conversion error when using runScript() on an expression dataset tag.
def getDistributorDropdownDataset(path):
'''
Get the position values and strings and return it as a dataset for use in a dropdown selector.
Args:
path (string) : string path to the dataset for the dropdown data
Returns:
dataset (dataset) : dataset of options
'''
parentTagPath = path.rsplit('/',1)[0]
tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
destinations = [tag.value for tag in system.tag.readBlocking(tagsToRead)]
headers = ['POS', 'DEST']
data = []
for i, destination in enumerate(destinations):
data.append([i+1, destination])
return system.dataset.toDataSet(headers, data)
Cannot convert "path" into into type: class java.lang.Integer
Why is it trying to convert the path into an integer? Where, even?
I would have to assume that one of the tag's that you're reading's value is actually "path" (unfortunate that it matches the function parameter name). Generally, you'll see this type of error when creating a dataset if the values in your data list are not of the same types.
The to*DataSet() functions will assume the type of the value in the first row for that column.
So for instance, if the first tag value is an integer, then the column will be typed as an integer column. If then next value is a string, you will get this error.
If you have a mix of integer values and string values then you will need to use the DatasetBuilder to explicitly specify that the column type should be String.
from com.inductiveautomation.ignition.common.util import DatasetBuilder
from java.lang import Integer, String
def getDistributorDropdownDataset(path):
parentTagPath = path.rsplit('/',1)[0]
tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
destinations = [tag.value for tag in system.tag.readBlocking(tagsToRead)]
builder = DatasetBuilder.newBuilder()
builder.colNames(["POS","DEST"])
builder.colTypes([Integer, String])
for i, destination in enumerate(destinations):
builder.addRow(i,destination)
return builder.build()
The path is not actually "path" that's just pseudo-code.
It makes less that 0 sense that it works in the script console but not from the runScript()
The very first row is Integer, String. I've even added type conversions just to be sure.
def getDistributorDropdownDataset(path):
'''
Get the position values and strings for a distributor and return it as a dataset for use in a dropdown selector.
Args:
path (string) : string path to the dataset for the dropdown data
Returns:
dataset (dataset) : dataset of options
'''
parentTagPath = path.rsplit('/',1)[0]
tagsToRead = [parentTagPath+'/'+str(num) for num in range(1,17)]
destinations = [str(tag.value) for tag in system.tag.readBlocking(tagsToRead)]
headers = ['POS', 'DEST']
data = []
for i, destination in enumerate(destinations):
row = [int(i+1), destination]
print row
data.append(row)
return system.dataset.toDataSet(headers, data)
You're using a tag path there as if it's going to give you tag value.
Edit: Wow i need coffee
Edit Edit: Wait no, the error explicitly states the value it's attempting to coerce, which looks like a tag path.