You can define your own scripts in TIBCO Spotfire by adding action controls in a text area. The scripts are written in IronPython and they allow you to incorporate simple actions or tools into your analysis without having to deploy complete AddIns to the server. The scripts have full access to the Spotfire API.
To be able to create analyses containing IronPython scripts, you need to belong to the group "Script Author" and have the license function “Author Scripts” under “TIBCO Spotfire Extensions” enabled. Select Tools > Administration Manager to make the necessary changes, or contact your Spotfire Administrator to do it for you.
To add a script action link or button to the text area:
Click on the Toggle Edit Mode button, , in the Text Area title bar.
Click on the Insert Action Control button, .
Response: The Action Control dialog is displayed.
Click on Script in the left-hand panel.
Type a Display text to be shown in the text area.
Select a Control type: Link or Button.
In the Available scripts list, click on the script of interest.
Comment: To define a new script, see Example scripts below.
Click on each parameter (if there are any) in the Necessary input for the selected script field and specify the Input for the selected parameter.
Comment: If the script needs some kind of input values, then these must be specified before the script can be executed. Examples of input could be a text value or a specification of a visualization or a page to work with.
When all script parameters have been defined, click OK.
Response: The action control is added to the text area.
Click on the Toggle Edit Mode button, , in the text area title bar to turn off the Edit mode.
Example scripts:
Below are more details about how to create and use a few example scripts in TIBCO Spotfire. These steps can also serve as instructions for how you should work when creating your own scripts.
To create the "Change visualization title" script:
In a text area in Edit mode, click on the Insert Action Control button, .
Response: The Action Control dialog is displayed.
Click on Script in the left-hand panel.
Click New....
Response: The New Script dialog is displayed.
Type the Script name: Change visualization title.
In the Script field, type or paste your script:
visual.Title = title
Click Add....
Comment: You need to specify the type of the parameters used in the script.
Response: The Add Script Parameter dialog is displayed.
In the Name field, type title.
Comment: This is the string parameter containing the visualization title.
From the Type drop-down list, select String.
Comment: The title must be a string which can be defined either by a simple text value, a string property or an expression.
If desired, add a Debug value which can be used for testing the script.
Click OK.
Response: The "title" parameter is added to the Script parameters list.
Click Add... again, to define the second parameter.
Response: The Add Script Parameter dialog is displayed.
In the Name field, type visual and select Visualization as the Type.
Comment: This parameter is used to point out which visualization to change the title on.
Select a Debug value visualization to use when testing the script.
Click OK.
Response: The "visual" parameter is added to the Script parameters list.
If desired, test the script by clicking Run Script.
Response: The selected visualization title is updated with the Debug value provided in the Add Script Parameter dialog. Click Undo in the New Script dialog to revert to the old title.
Click OK to close the New Script dialog.
Response: The script is added to the Available scripts list in the Action Control dialog and the defined parameters are shown in the Necessary input for the selected script list (as long as the script is selected in the Available scripts list).
Continue with To use the "Change visualization title" script below.
Tip: To change the title of the active visualization, use the following script:
Document.ActiveVisualReference.Title = title
To use the "Change visualization title" script:
Define a display text and a control type as described in "To add a script action link or button to the text area".
Make sure that the "Change visualization title" script is selected.
Click on the first parameter, title, in the Necessary input for the selected script list.
Response: The Input for the selected parameter settings for title become available.
Determine whether to define the title using a predefined Value, a Property or an Expression.
Comment: In this example, we will assume that the title is specified using a Property.
Click Select Property....
Response: The Select Property dialog is displayed.
On the Document Property tab, click New....
Comment: If a suitable property is already available, you can select it in the list and go to step 10.
Response: The New Property dialog is displayed.
Type a suitable Property name, for example, visualization.title.
From the Data type drop-down list, select String.
Comment: The title must be a string.
Type a Value to be the first (default) value of the property. For example, My Visualization Title.
Click OK.
Response: The new property is selected in the Select Property dialog.
Click OK.
Response: The Property field in the Action Control dialog is updated to show the expression syntax for the property you just defined.
Click OK.
Response: The action control is added to the text area.
Click on the Toggle Edit Mode button, , in the text area title bar, to turn off the Edit mode.
Test the action control by clicking on it in the text area.
The property controlling the visualization title could in turn be modified using a property control (for example, an input field) in the text area. See Using Properties in the Analysis for examples of how you can add property controls.
To create the "Change filtering scheme" script:
In a text area, click on the Insert Action Control button.
Response: The Action Control dialog is displayed.
Click on Script in the left-hand panel.
Click New....
Response: The New Script dialog is displayed.
Type the Script name: Change filtering scheme.
In the Script field, type or paste your script:
from Spotfire.Dxp.Application.Filters import FilterPanel
# Get hold of the filters panel for the current page.
panels = Document.ActivePageReference.Panels
# The return value and out parameters are returned as a tuple
# in IronPython and can be bound with pattern matching.
(found, filterPanel) = panels.TryGetPanel[FilterPanel]()
# Find the filtering selection named "Filters2"
# and set it as current.
for filteringScheme in Document.FilteringSchemes:
filteringSelection = filteringScheme.FilteringSelectionReference
if filteringSelection.Name == "Filters2":
filterPanel.FilteringSchemeReference
= filteringScheme
Comment: The included example script expects to find a filtering scheme called "Filters2" and changes the filtering scheme of the active page to the Filters2 filtering scheme.
Click OK to close the New Script dialog.
Response: The script is added to the Available scripts list in the Action Control dialog.
Continue with To use the "Change filtering scheme" script below.
To use the "Change filtering scheme" script:
Define a display text and a control type as described in To add a script action link or button to the text area above.
Make sure that the Change filtering scheme script is selected.
Click OK.
Response: The action control is added to the text area.
Comment: This script requires no input from the end users, but if there is no "Filters2" filtering scheme in the analysis, then nothing will happen when the action control is clicked.
Click on the Toggle Edit Mode button, , in the Text Area title bar, to turn off the Edit mode.
Test the action control by clicking on it in the text area.
See also: