Marking programatically



This script came from here, which include the bones. Here is the meat:
## we need the from/import statements so Spotfire understands the code
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection
## get count of rows in data table
rowCount = dataTable.RowCount
## create index sets required to loop over rows
rowsToInclude = IndexSet(rowCount,True)
## this index set we will populate with rows to mark - the False specifies it is not populated
rowsToMark = IndexSet(rowCount,False)
## create a cursor so we can refer to the column of interest
columnCursor = DataValueCursor.CreateFormatted(dataTable.Columns["Value"])
## check if our document property was set to None or not
if dropDownValue != "":
    ## Now loop over the rows in the data table
    for row in dataTable.GetRows(rowsToInclude, columnCursor):
        rowIndex = row.Index
        ## use the cursor to compare the column row value to our drop down value
        if int(columnCursor.CurrentValue) > int(dropDownValue):
                ## if it passes the condition add it to our new indexset
                rowsToMark.AddIndex(rowIndex)
else:
    ## if the user has selected None as the option for the drop down, clear the indexset
    rowsToMark.Clear()
## Now finally mark the rows in the data table
Document.ActiveMarkingSelectionReference.SetSelection(RowSelection(rowsToMark), dataTable)

No comments: