How to develop IronPython scripts in TIBCO Spotfire® and their limitations
By:
Last updated:
2:27pm Jun 06, 2018
Back to main IronPython scripting page

Introduction

Scripts are small IronPython code snippets that can be written and executed on the fly. They require no compilation and deployment. During run time, they access both Python, .NET and Spotfire libraries. Scripts are intended to perform automation tasks and are a part of the loaded Spotfire Document (DXP). Each analysis can have its own set of scripts, and like other parts of the analysis, must be manually transferred between different files if needed. Certain Spotfire libraries can not be used in the script scope since they require specific run time components. Another thing to consider is that scripts are platform independent and can not use any Windows specific GUI components such as MessageBox if they are intended to run on the Web Player or in the cloud.

Libraries

We recommend only using .NET and Spotfire libraries. This also makes converting between the Spotfire extensions and IronPython scripts later on easier.

Limitations

Scripts are executed in isolation from the rest of the running Spotfire code. This is to ensure that faulty scripts cannot crash the running client and also provide security to avoid malicious scripts. To provide further security, scripts must also be trusted before they are used. Spotfire use a undo/redo system to give the user the option to revert the changes done after the script has executed.

Transactions

To allow Spotfire control over script executions, all scripts are wrapped in a transaction. This transaction makes all actions performed in the script undoable. This has however certain drawbacks. For the transaction to work, all individual modifications done in the script will be compressed and applied in a single step when the script is finished. This sometimes affect objects modified in the script. Changing a property for instance might require the plot to recalculate before the action is done. When the script finished, all actions on the document is performed.

Examples of IronPython compared to C#

# Import Spotfire libraries
# C# => using Spotfire.Dxp.Application.Visuals.TablePlot;
from Spotfire.Dxp.Application.Visuals import TablePlot

# Using Microsoft libraries
import clr
clr.AddReference('Windows.System.Forms')
from Windows.System.Forms import MessageBox

# Type identifiers
# C# => TablePlot tableplot = myvis.As<TablePlot>()
tableplot = myvis.As[TablePlot]()

Editing

The Spotfire editor provides some basic features to aid debugging scripts (e.g. use the Print statement to output values), but does not support syntax checking or autocomplete. It is possible (although not trivial) to use an external editor to edit complex scripts - see How to use an external editor to edit IronPython scripts - with autocomplete and syntax checking for more information

References