IronPython 示例脚本
本主题列出了多个示例脚本,通过单击文本区域中的操作链接或按钮可执行这些示例脚本。
另请参见向文本区域或图表项目添加脚本操作,了解更多示例以及有关如何向文本区域添加脚本的详细说明。有关更多示例以及在 Spotfire 中使用脚本的教程,请参见 Community 中的在 Spotfire 中编写 IronPython 脚本。
提示: 如果表达式参数绑定到字符串属性值,可以使用具有各种预定义表达式选择的属性控件(例如下拉列表)来创建可在其中以简单方式将复杂表达式分配给图表轴的分析。有关如何添加属性控件的信息,请参见向文本区域添加属性控件。
提示: 通过使用“运行脚本”运行 IronPython 脚本(无需关闭“新建脚本”对话框),可以对此脚本进行测试。由脚本定义中的
print
所标记的任何对象将显示在“输出”列表中。单击“撤消”可以撤消,以在完成后从文档中删除测试的结果。刷新计算、按需数据和数据函数
# 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()
将 SBDF 文件中的列添加到当前文档中的数据表
# 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)
将特定图表(“可视化表示”)用作输入,然后更改图表的 X 轴
# 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
IronPython 版本
默认情况下为新脚本选择支持的最新 IronPython 版本。可以为每个脚本指定 IronPython 版本,这意味着分析可以包含不同 IronPython 版本的脚本。如果分析包含 IronPython 版本较旧的脚本,无需将它们转换为较新的 IronPython 版本,除非您想使用仅在较新版本中可用的脚本功能,或者不再支持该版本。有关 IronPython 版本之间差异的信息,参阅官方 IronPython 文档。
在事务中执行
取消选中“在事务中执行”复选框可避免在文档事务中执行脚本。如果 IronPython 脚本包含无法在事务内正常执行的操作,可能必须取消选中此复选框。
父主题: 向文本区域或图表项目添加脚本操作