Copying a dataset?

I have a dataset from a from a root container custom property. In a script, I would like to make a new copy of it. Rigiht now I am doing that like so

def my Func(ds):
    copy_ds = system.dataset.toDataSet(system.dataset.toPyDataSet(ds))

but I think there is probably a better way to do this, and I worry about converting to a py and the back messing something up. Anyone know how to make a copy of a dataset directly?

Why do you need a copy? (Datasets are supposed to be immutable, and safe to assign in multiple places.)

FWIW, passing a dataset as the single argument to a BasicDataset constructor will make a copy of the contents.

In our application, when we have a editable table, we have two custom propreties, ReadData, which is a SQL Binding, that the table.data points to, and a WriteData custom property, where user changes are logged to. Then, we send off ReadData and WriteData to a function to parse for difference and do dynamic SQL.

Except now, we have a very old window, with 96 template components instead of a table. It still has a ReadData but the thinking is we will programatically create a WriteData dataset, so we can utilize the same function to run SQL. So I wanted to make a copy of the ReadData first (as there are plenty of columns not on the GUI that should be included with WriteData for the difference parsing to work right), before iterating through the components and making appropriate updateRow statements to WriteData.

How would I call the BasicDataset constructor?

from com.inductiveautomation.ignition.common import BasicDataset

newDS = BasicDataset(otherDS)

FWIW, I would recommend eliminating WriteData—just unidirectionally bind the table’s data property to the ReadData (which presumably is not polling). Then you can compare cells on the table to cells in ReadData to highlight changes, etc. (Cell edits would replace table.data.) When you refresh ReadData after your save script writes to the DB, its update will flow through to the table display naturally.

2 Likes