Message handler script with perspective table component property

image
In my message handler code, I have a script trying to access the selection data in table component in perspective. I am getting error that data is not a attribute:
image

but in the table.props. selection I can see the data:
image

does anyone know how i can fix this?
thanks!

I would need to see your full script to be sure, but the error message calls out line 8. Your provided code is only a few lines long and starts at line 2 in the script editor, so I can only assume you make a reference to selectedTags outside of the code you posted here. As selectedTags is a temporary variable available ONLY within the loop, your later reference is not valid.

Providing the script including line 8 would give us a better idea as to the issue.

image
sorry line 8 is the newTag line

Oh, I misread the error message.

Assuming your table has a column named “path”, I think you want something like this:

for selectedTag in self.props.selection.data:
    newTags.append(selectedTag.path)

self.props.selection is an object, and so when you loop over it, you’re getting the keys of the object, and these keys are strings (unicode). This is why you’re seeing the clarification that the unicode object has no attribute “data”.

that works, thank you for your help!

1 Like

hello, regarding to the script, I have an event script on table component to delete a plot in time series chart. I also have a message handler on timer series chart. My goal is to delete certain plot by toggle certain column in table. I try to use axis in the plot property to decide which plot i delete. I can’t quite get it to work. Could you please see what is problem might be? thanks sorry I am quite new for ignition.

my event script on table component:

	if event.column =='delete':

	   system.perspective.sendMessage('removeplot',{'axis':plot['axis']})

my message handler script on time series chart:

	toggleTag = payload['axis']
	togglePen = None
	plots = [plot for plot in self.props.plots]
	for plot in plots:
	    if plot.trends['axis'] == toggleTag:
	        togglePen = plot 
	    plots.remove(togglePen)

There’s a lot of moving pieces here, so I need some more information:

  1. What Event is actually invoking the script action you supplied?
  2. If you print out the column, what do you see? I’m betting it’s not a simple string (unicode) - it’s probably an object, so it’ll never equal “delete”. (see example “A”)
  3. Your message handler is modifying a local plots variable, but you aren’t doing anything with the new data. In your message handler, plots is a COPY of the data in self.props.plots. You then modify the copy and remove an entry from the list. But you haven’t changed the original data. (See example “B”)

Example A:

system.perspective.print(event.column)
if event.column == 'delete':
    system.perspective.sendMessage('removeplot',{'axis':plot['axis']})

Example B:

toggleTag = payload['axis']
togglePen = None
plots = self.props.plots
for plot in plots:
    # This next line will also fail, because trends is a list. you probably
    # want plot.trends[0].axis, but I'm not a Time Series Chart expert
    if plot.trends['axis'] == toggleTag:
        togglePen = plot 
    plots.remove(togglePen)
self.props.plots = plots  # This is the important line

hello, I got that work, so basically i use the axis to match the a parameter in a column selection, and use that to trigger the trends to be deleted. My problems was the script parts, but after I modify the example B you provide it, it works, thank you!

1 Like