Dynamic property path in table

Hi there

I am trying to change the style property of a table dynamically, it is a table with times as rows and days as columns

the columns are d1,d2,d3 up to d31

I want to change the tables style depending on the time, so I have two nested loops

for i in range(0,12,1):
			
		for j in range(1,32,1)
		
			self.props.data[i].d1.style.classes = "LoadShedding/Cell_Normal"

I want to iterate through this from d1 to d31 using the ‘j’ variable. How do I accomplish this?

I need to select more than one cell at a time, so I can’t just modify the selected values in the table’s properties

I am using perspective 8.1

Hi @Adriaan.leRoux, you can do this via creating the data structure on the binding.

This may help, but I can explain further if you need it.

Edit: updated the link, I posted the wrong one :sweat_smile:

1 Like

Thanks for the reply.

Excuse the ‘C++’ speak, but are you essentially saying that I should not think about this data[] array as an array of classes but instead see it as an array of strings? These strings being formatted like a you would see if you copied and pasted that index into notepad? JSON right?

No worries. Right, this is how I interpret it (which may not be correct, but it’s how it works in my head). The data array is an Ignition array of Ignition objects. However, when you create the data array via a script binding, Ignition will implicitly convert python lists to Ignition arrays and python dictionaries to Ignition objects.

Note: be careful as I believe Ignition types do not implicitly convert back (e.g. an Ignition object will not convert back to a python dictionary implicitly).

The link is an example of creating the data array of objects in a way that allows you to style each individual cell. For the column dictionary key you should be able to use string concatenation to give you the appropriate key for your column.

1 Like

Thanks a bunch, I will let you know how it goes

1 Like

Try this:

for i in range(0,12,1):
	for j in range(1,32,1)
		dj = getattr(self.props.data[i], 'd'+str(j))
		dj.style.classes = "LoadShedding/Cell_Normal"

getattr is a python/jython builtin function for property (attribute) access. See also setattr for leaf attributes.

2 Likes

@pturmel I looked at that function, but it seemed to return actual values, not a reference. Is that returning a pointer?

It should return the object. Stringification would happen if you used it in any non-object way.

1 Like

@pturmel Works like a charm! Thanks!