Wanting to Add Data to Dataset

I am trying to add Tag Values to a dataset in a table. I want to pull the data from DS1 which = Minor Bin 1, Minor Bin 2, Minor Bin 3, etc… I am getting the bin names from a db table via query. How can I add a new column to this table that will show what mode the Bin is in.

The tagpath for the Bin Modes is [default]Minor Bins/Minor Bin 1/Mode and etc…

system.dataset.addColumn() should do the trick. :slight_smile:

https://docs.inductiveautomation.com/display/DOC80/system.dataset.addColumn

I guessing I do not know how to add the tag path into the script.

To get the tag data use system.tag.read('tagPath').value. To get the path you can right click on the tag and use Copy Path or you can click on the little tag icon to the right of the scripting window. This will let you browse for the tag.

I’m may not be following correctly, but here is what I think you have (or, it’s how I read it).

  • You have a table component (I’ll call it ‘table’), that has information on it for these Minor Bins.
  • The names of the bins are in the first column of the table.
  • You want to read the tags for the bin modes. The bin names in the table are also, happily, part of the tag path.

If that is true, the script to make your tag list would look something like this:

### Verbose method

# Get the table component, since we will read from and write to it. 
table = path.to.table

# Get the table's dataset
dataIn = table.data

# Get the bin names. [0] Assumes the bin names are in the first column
binList = dataIn.getColumnAsList[0]  

# define our tag path. %s will let us subtitute a string later.
baseTagPath = '[default]Minor Bins/%s/Mode'

# Make an empty list to store the tag names
tagList = []

# loop through the bin names
for bin in binList:
	# Add a new tag path, substituting in the (hopefully) actual bin name.
	tagList.append(baseTagPath % bin)

# Read the list of tags we just created.	
tagsIn = system.tag.readBlocking(tagList)

# Make an empty list to hold our tag values
values = []

# Loop through the tag obects.
for tag in tagsIn:
	# add each tag value to the values list
	values.append(tag.value)

# Add the column to the dataset with a column name 'mode' and write it to the table.
table.data = system.dataset.addColumn(dataIn, values, 'mode')

For those who prefer list comprehensions:

# Get the table's dataset
dataIn = path.to.table.data

# Get the bin names. [0] Assumes the bin names are in the first column
binList = dataIn.getColumnAsList[0]  

# define our tag path. %s will let us subtitute a string later.
baseTagPath = '[default]Minor Bins/%s/Mode'

# Make the tag name list
tagList = [baseTagPath % bin for bin in binList]

# Read the list of tags we just created.	
tagsIn = system.tag.readBlocking(tagList)

# Make an empty list to hold our tag values
values = [tag.value for tag in tagsIn]

# Add the column to the dataset with a column name 'mode' and write it to the table.
path.to.table.data = system.dataset.addColumn(dataIn, values, 'mode')
1 Like

Hi sir, does "getColumnAsList" still working on version 8.0.14? it says 'object has no attribute 'getColumnAsList''

Depending on how the data is coming in, it may not be in that particulat Dataset interface.

from com.inductiveautomation.ignition.common import BasicDataset

dataIn = BasicDataset(path.to.table.data)