Bidimensional array indexing

Hey there!

Just a simple question. I am trying to access and modify an element in a bidimensional array/list, but it is not working as I expected and I am missing something. I cannot find anything similar in the manual or forum.

This example is just for testing with onClick action in a normal button:

X = [["A","B"],["C","D"]]

self.getSibling("Label_0").props.text = X[0]
#ok, I see ["A","B"]

self.getSibling("Label_0").props.text = X[0][0]
#ok, I see A

Y = system.tag.readBlocking("[default]NewTag")[0].value

self.getSibling("Label_0").props.text = Y[0]
#I see ['A','B']

self.getSibling("Label_0").props.text = Y[0][0]
#I get literally: [

Could anyone explain the difference?

And then, how would I modify any element in the bidimensional list? Would it be different if work with the X array or Y array? Example (when pressing another button):

X[0] = ["A","B","F"]
Y[0] = ["A","B","F"]

X[0][0] = "Hello"
Y[0][0] = "World"

Thanks in advance,

Ignition’s tags don’t support anything beyond 1d arrays. When you write the 2d array into it and then read it back I think you’re getting a string representation of some object in memory instead of a value you can work with.

Thanks for the quick respone @Kevin.Herron ,

And do you have a tip about how to solve this?

I would like to work with 2d arrays because:

  1. dataset cells do not support arrays
  2. all the cells inside a column of a dataset must be the same type

Maybe work with UDTs?


Isn’t a dataset basically a 2d array?

A dataset cell containing an array would be a 3rd dimension.

Yes, I would need that 3rd dimension.

Depending on the column and the row, the cell must contain a different array inside.

My list would be then something like this (2x2 matrix where the cells are arrays):

X = [[array1,array2],[array3,array4]]

I also need to keep those values in memory, and that is why I thought about writing into tags.

If you don’t need to access the data from multiple scopes (Vision Client vs Gateway) you can maybe just store it in a global variable or the globals map.

Also worth considering storing some amount of the content in a json structure. You could use a “document” tag and have access to the content through the tag editing GUI. That document holding everything could easily be pushed anywhere/everywhere as an encoded json string.

1 Like

@Kevin.Herron I need to access the data from perspective. I am developing a SCADA project only using perspective. Not sure if I accessing from a perspective client would create any problem.

@rcrownover I am a little newby to Ignition. Could you give a simple example of your idea?


I just tried this example and I am still stuck:

On a first button:

X = [["A","B"],["C","D"]]
jsonString = system.util.jsonEncode(X)
#NewTag type is document, and I can see that the array is written (attached image)



On a second button:

jsonString = system.tag.readBlocking("[default]NewTag")[0].value

#all of this looks ok:
self.getSibling("Label").props.text = jsonString
# [["A","B"],["C","D"]]
self.getSibling("Label").props.text = jsonString[0]
self.getSibling("Label").props.text = jsonString[0][0]

#but I cannot modify like this:
jsonString[0][0] = "Z" # or even jsonString[0][0] = another array

I tried using system.util.jsonDecode but not working or not sure how to use it.

Thanks guys,

This has no sense, is an array after all.

I feel you are not in a good path but I’ll help you to at least write back to the tag with new value.

X = [["A","B"],["C","D"]]
jsonString = system.util.jsonEncode(X)

jsonString = system.tag.readBlocking("[default]NewTag")[0].value
items = []
for i in range(len(jsonString)):
	idx = []
	for k in range(len(jsonString[i])):

items[0][0] = "Z"
newJson = items
jsonString = system.util.jsonEncode(newJson)