Using python to add tabs to a tabstrip

Is there an easy way to add a new tab to a tabstrip using scripting?

Yes. The Tab Strip Component has a dataset called Tab Data that holds the tabs. You can add another tab via Python by adding another row to the Tab Data dataset.

You could use the system.dataset.addRow scripting function to add another row to the dataset.

You could view the Tab Data dataset using the Dataset Viewer in the Designer and copy the contents and then paste the contexts into a text file to see the exact format that you need for each column for your Python script.

Once you have the dataset pasted into a text file it is easy to wrap one of the lines of text with Python list brackets “[” and “]” to make a Python list out of a row of the dataset. Then just change whatever columns you want to change. Then use system.dataset.addRow or other dataset function to change the dataset in Ignition.

There are many ways to change a dataset in Ignition, and that is all that you need to do to change tabs in the Tab Strip Component.

Here’s an example script. I used this code in a Root Container mouseClicked event script. The the row assignment should be a single line.

row = ["Tab 5","Tab 5","color(250,214,138,255)","","-1","-1","color(0,0,0,255)","color(238,236,232,255)","font(Dialog,PLAIN,12)","color(238,236,232,255)","color(238,236,232,255)","","-1","-1","color(0,0,0,255)","color(238,236,232,255)","font(Dialog,PLAIN,12)","color(238,236,232,255)","color(170,170,170,255)","false","true",""]
tab = event.source.getComponent('Tab Strip')
tab.tabData = system.dataset.addRow(tab.tabData,0,row)


Thanks for your reply. I’m probably over thinking this. I really want to duplicate the 22 columns that describe the existing tab to create a new tab. That way a future developer can control the tab properties for all generated tabs by way of modifying a base tab (the that’s initially on the tab strip), removing the dual maintenance of tinkering with that tab’s appearance, and then modifying the row data to match the tinkering. So, I was hoping for a duplicate function of sorts followed by a system.dataset.setValue(), instead of having to walk through the tabData columns.

So, in short, I cannot figure out how to start with the tabData, grab the first row, and add that row and modify it. I tried this sort of thing:

row = system.dataset.toPyDataset(tabData)[0]

system.dataset.addRow(tabData, row)

But, ignition is reporting that row cannot be coersed into a Pysequence

Yes, I see. You can do it that way, no problem.

A PyDataSet row is not a PySequence, but it is easy to make it one. Use the list function.


row = list(system.dataset.toPyDataSet(tab.tabData)[0])
tab.tabData = system.dataset.addRow(tab.tabData, 0, row)

That’s the ticket. Thanks!