Passing a table to runScript

In Vision, I want to use a label component which shows the number of selected rows in a table.
I can get the number of selected rows in a table with .getSelectedRowCount(), so I wrote:

def getSelectedRowCount(table):
return table.getSelectedRowCount()

Now I’m trying to bind the label’s text property to the following expression:

runScript(“utils.getSelectedRowCount”, 0, {Root Container.MyTable})

but I get the error:

AttributeError: ‘NoneType’ object has no attribute ‘getSelectedRowCount’

so I guess the table object is not passed correctly, which I suspected wouldn’t work even before trying, but then how do I accomplish the task?

You can bind it to


No, that doesn’t tell me the number of selected rows in the table.

Gah! Sorry I didn’t see the selected part.
What I would do for this is create a custom property on the table called selected as an integer.
Then in the propertyChange event of the table put the following code

if event.propertyName=='selectedRows':

Then you just bind the label to that custom property.

Sorry but unless I’m missing something tables have no “selectedRows” property (the list of selected rows can only be obtained by calling .getSelectedRows() on the table object).

you missed the part of the code



I mean that event.propertyName can never be “selectedRows”, since vision tables have no such property.

Power Tables do, if you are using a regular table create the same custom property on the table, and then in the Mouse Released script put

event.source.selected = event.source.getTable().getSelectedRowCount()

Power tables in vision also do not have a “selectedRows” property.

I’d prefer to avoid the mouse released event approach since rows in my tables are selected/deselected by external events and controls, and not necessarily through clicking on the table itself.
I could also update the selected row count inside those other components and events when they are fired, but it’s an approach that doesn’t scale.

@MMaynard 's solution will indeed get you the result you need (though I see you have other requirements as well), without the overhead of having that script. As for why you can’t pass the table, Expressions do not allow for passing components. If you attempt to use the GUI (v8.0 and newer), you’ll actually receive an error dialog, informing you that you must supply a bindable property of the component.

Can I then pass the table’s full path as a string to the python code then get the object back when in python starting from the path string?

Actually, they do. It just isn’t bindable. And doesn’t generate propertyChange events. But it is available to scripts.

1 Like

Well, then I suggest updating the docs, no mention of that here

1 Like

In theory, yes, but I’m not the one to ask in regard to how to accomplish such a feat.

This is possible when runscript calls a custom method of a component, as you can use the self argument to indirectly access other components in that window. It is possible with the objectScript() expression function (part of Simulation Aids) without a custom method thanks to its local variable.

1 Like