How to retrieve data marking selection using IronPython in TIBCO Spotfire®
Last updated:
12:07am May 10, 2017
Back to main IronPython scripting page

Introduction

There is more than one way to retrieve marking selection, depending on the values to be retrieved. The following example shows how to retrieve values from only one column, using the DataValueCursor class.

Code sample

# Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.

from System.Collections.Generic import List
from Spotfire.Dxp.Data import *

# Create a cursor for the table column to get the values from.
# Add a reference to the data table in the script.
dataTable = Document.Data.Tables["tableName"]
cursor = DataValueCursor.CreateFormatted(dataTable.Columns["yourColumnName"])

# Retrieve the marking selection
markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable)

# Create a List object to store the retrieved data marking selection
markedata = List [str]();

# Iterate through the data table rows to retrieve the marked rows
for row in dataTable.GetRows(markings.AsIndexSet(),cursor):
	#rowIndex = row.Index ##un-comment if you want to fetch the row index into some defined condition
	value = cursor.CurrentValue
	if value <> str.Empty:
		markedata.Add(value)

# Get only unique values
valData = List [str](set(markedata))

# Store in a document property
yourVariableName = ', '.join(valData)
Document.Properties["yourDocumentPropertyControl"] = yourVariableName

 

Note that you can create a cursor for each of the columns for which you intend to retrieve values.

Note that it is possible to reference the marking used in the visualization by name, instead of using Document.ActiveMarkingSelectionReference. For example, you can use:

markings = Document.Data.Markings["YourMarkingName"] 

 

References

 

License:  TIBCO BSD-Style License

Feedback (2)

Don Johnson 12:17pm Oct. 09, 2017

Is thre any better way to store these marked rows in Tags/List ? Document property may not work when you have larege numbers of rows marked.

 

satish_thorat 8:10am Oct. 09, 2017