IronPython Example Scripts


This topic lists a number of example scripts that can be executed by clicking on action links or buttons in the text area. See Using Scripts in the Text Area for more examples and detailed instructions on how to add scripts to a text area.

Refresh of calculations, on-demand data and data functions:

# Example script that refreshes a table driven by
# a calculation, a data function
# or an information link loaded on demand.
# The script takes a parameter "table" of type DataTable

if table.IsRefreshable and table.NeedsRefresh:
   table.Refresh()

Add columns from an SBDF file to a data table in the current document:

# This script adds columns from an sbdf file to a data table
# in the current document.
#
# Four arguments are expected:
#   table - The data table in the current document
#           that columns will be added to.
#   path - The path to the sbdf file with columns to add.
#   ColumnNameInTable - A column in the data table.
#   ColumnNameInFile - A matching column in the sbdf file.
# The columns are used to join new data to the current data.

from Spotfire.Dxp.Data.Import import SbdfFileDataSource
from Spotfire.Dxp.Data import AddColumnsSettings, JoinType, DataColumnSignature, DataType

# Create the join condition map. The column with the name
# specified in ColumnNameInTable from the current data table
# will be joined with ColumnNameInFile in the sbdf file.

columnInTable = DataColumnSignature(table.Columns[ColumnNameInTable])
columnInFile = DataColumnSignature(ColumnNameInFile, DataType.String)
joinConditionMap = {columnInTable : columnInFile}

ignoredCols = [ ]
settings = AddColumnsSettings( joinConditionMap, JoinType.InnerJoin, ignoredCols)
ds = SbdfFileDataSource(path)
table.AddColumns(ds, settings)

Use a specific visualization ("Visual") as input and then change the X-axis of the visualization:

# Sets the value of the XAxis Expression of a visual.
# This script expects two arguments:
#   visual - The visual to the set the X-axis expression on.
#   expression - The expression to set.

from Spotfire.Dxp.Application.Visuals import VisualContent

# Get the content of the visual. Use the most general type
# so that the script works for all VisualContent classes that
# have an X-axis property.
vc = visual.As[VisualContent]()

vc.XAxis.Expression = expression

Tip: If the expression parameter is tied to a string property value, you can use a property control (e.g., a drop-down list) with a number of predefined expression alternatives to create an analysis where complex expressions can be assigned to visualization axes in an easy way.

See also:

How to Use the Text Area

Action Script Examples