Hi there.
How can I get the first and last values of every column from a power table?, selected values must be <> 0 like next image
Hi there.
How can I get the first and last values of every column from a power table?, selected values must be <> 0 like next image
From your picture, it doesn't look like you are simply wanting the first and last non-zero values; it looks like you are wanting the first and last non-zero values that are currently displayed in the scrollpane? Is this correct?
If you are simply trying to get the first and last non zero value from the dataset as independent lists, this script will do that for you:
powerTable = event.source.parent.getComponent('Power Table')#Replace with relative powerTable path
data = powerTable.data
topRow = []
lastRow = []
for column in range(data.columnCount):
columnData = data.getColumnAsList(column)
zerolessData = [value for value in columnData if value != 0]
topRow.append(zerolessData[0] if zerolessData else None)
lastRow.append(zerolessData[-1] if zerolessData else None)
print topRow
print lastRow
It gets each column as a list, removes the zero values, and then makes lists with the first and last values that remain in each column.
However, if you only want the first and last non zero values of the visible portion of the table, as your picture indicates, then you will need to get the visible indexes using viewport's view rectangle's location and size. Here is a script that does this:
from java.awt import Point
powerTable = event.source.parent.getComponent('Power Table')#Replace with relative powerTable path
table = powerTable.table
data = powerTable.data
viewport = table.parent
viewRect = viewport.viewRect
startIndex = table.rowAtPoint(viewRect.location)
endIndex = table.rowAtPoint(Point(viewRect.location.x, (viewRect.location.y + viewRect.size.height)))
topRow = []
lastRow = []
for column in range(data.columnCount):
columnData = [data.getValueAt(row, column) for row in range(startIndex, endIndex)]
zerolessData = [value for value in columnData if value != 0]
topRow.append(zerolessData[0] if zerolessData else None)
lastRow.append(zerolessData[-1] if zerolessData else None)
print topRow
print lastRow