Script to generate bindings

Good day!

I have a table component in perspective, showing different tags of different equipment.
Now for testing I have configured the DATA prop of the table manually, linking the fields with the Tags in the Tag browser.

But this is not going to be possible for hundreds of tags, so I would like to build an script to add this bindings automatically.

Is there a way to add a binding? for the moment I read the tags I need with system.tag.readblocking() and I assign those values to the prop.data of the table, but this is not a dynamic way to bind, if the tag changes, the value will not be shown.

Any idea?? thanks a lot!!!

You can generate a dataset or an array of objects and bind that to the table's data property. Here's an example of the latter;


folderPath = "[path/to/tags]"
tagPaths = system.tag.browse(folderPath)
tagObjects = []

for tag in tagPaths:
	tagPath = folderPath + "/" + tag["name"]
	tagValue = system.tag.readBlocking([tagPath])[0].value
	tagObject = {
		"tagName": tag["name"],
		"tagValue": tagValue
	}
	tagObjects.append(tagObject)

return tagObjects

You'd then configure 2 column objects tagName and tagValue. This will populate your table with tags from your tag provider. You can check out this thread, I think there could be a lot of useful info for you;

Perspective table edit example, please - Ignition - Inductive Automation Forum

If you don't need the values to be refreshed in "real time", you can generate the table by reading all the tags as described by @Fran_Dujmovic, and refresh it every x seconds.

If you want to have actual bindings to each tags, you can't script that in ignition, but you can generate the configuration with a script.
You can configure a row, with its bindings, then copy the table and paste it in an editor so you can see what it looks like. It's in json format.
Modify it with a script, then copy the resulting json and paste it back in your view.

Fran, thanks for the link to my post. I don't think it's what Jose requires as it won't update if any of the tags change value.

I think the easiest option is,

  • Create a simple coordinate view with a tagPath parameter.
  • Add a Label Component to the view and create a tag binding on the label using the tagPath parameter.
  • Render the table's value column as a view and select the view created above.
  • Pass the tag path to the view instance.

You should be able to generate the list of instances by script fairly easily once you have the list of tags.

2 Likes

Eh I didn't think of that.
I'm not sure if I love or hate it.

The table component has terrible behavioral side effects if it is fed changing information in props.data. Breaks row selection and paging, usually.

If you want "live" data in a table, use cell rendering views with indirect bindings inside.

4 Likes

I see, thanks. I guess I love it then.

2 Likes

Yeah I guess I misread that part, sorry. What Phil mentioned regarding the use of cell view renders is the way to go.

1 Like