Jump to content
  • How to retrieve data marking selection using IronPython in Spotfire®


    This article explains how to retrieve data marking selection using IronPython in Spotfire®

    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

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...