[TIBCO Spotfire] Mark rows via IronPython

Here's a sample script to programmatically via IronPython mark rows with a particular value (set GRAPH as script parameter pointing to the visualization you want to work on):

from Spotfire.Dxp.Data import DataPropertyClass
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from System import String

# get object reference
vc = GRAPH.As [VisualContent] ()
dataTable = vc.Data.DataTableReference

# get marking
marking = vc.Data.MarkingReference

rowCount = dataTable.RowCount
rowsToInclude = IndexSet (rowCount, True)
rowsToSelect = IndexSet (rowCount, False)

cursor1 = DataValueCursor.CreateFormatted (dataTable.Columns ["COLUMN_NAME"])

#Find Records by looping through all rows
idx = 0
for row in dataTable.GetRows (rowsToInclude, cursor1):
    found = False
    aTag = cursor1.CurrentValue
    print aTag
# if there’s a match, mark it
    if aTag == VALUE:
        rowsToSelect [idx] = True
        print idx
    idx = idx + 1

#Set Marking
marking.SetSelection (RowSelection (rowsToSelect), dataTable)

No comments:

Post a Comment

With great power comes great responsibility.

Da grandi poteri derivano grandi responsabilità.