IronPython scripts intro

An IronPython script can be added to a Spotfire report through the Text Area visualization. To add an IronPython script to the report:

1)       Add a Text Area visualization to the active page.
2)      Right-click on the new Text Area visualization and click “Edit Text Area”.
3)      Find and click the “Insert Action Control” toolbar button.
4)      The Action Control window will open. In the left-hand list, select “Script”.
5)      Type in a “Display text”.
6)      Click the “New…” button on the right-hand side of the window.
7)      Type in a “Script name” at the top of the “New Script” window.
8)      Copy or type in the IronPython code into the “Script” window.
9)      Click the “Run Script” button to run the IronPython script.

Spotfire has many different ways to interact with IronPython scripts. Below is a list of helpful examples of ways to trigger IronPython scripts.

  1. On document property change
    1. https://community.tibco.com/wiki/how-execute-ironpython-script-tibco-spotfire-when-document-property-changes
  2. On button click
    1. https://docs.tibco.com/pub/spotfire/6.5.0/doc/html/text/text_using_scripts_in_the_text_area.htm
    2. https://techgoje.wordpress.com/2014/12/23/spotfire-ironpython-reset-markings/
  3. On dropdown selection
    1. https://community.tibco.com/wiki/example-script-modify-which-columns-are-shown-table-plotOn graphical table column enteraction
    2. https://docs.tibco.com/pub/spotfire/6.5.0/doc/html/text/text_action_script_examples.htm
  4. On filter change
    1. http://spotfired.blogspot.com/2015/10/update-doc-property-trigger-ironpython.html
    2. https://community.tibco.com/questions/how-trigger-ironpython-script-filter-changes
    3. https://www.cambridgesoft.com/support/EnterpriseSupport/KnowledgeBase/FAQ/details/Default.aspx?TechNote=3210
  5. On marking selection
    1. http://bispotfire.blogspot.com/2015/06/executing-python-script-based-on.html
  6. On report open
    1. https://community.tibco.com/questions/trigger-python-script-page-load
    2. https://support.tibco.com/s/article/Tibco-KnowledgeArticle-Article-44163?_ga=2.239220867.1277363987.1515438057-1300154003.1513629197
    3. https://support.tibco.com/s/article/Tibco-KnowledgeArticle-Article-45867?_ga=2.239220867.1277363987.1515438057-1300154003.1513629197
  7. On clicking a tab
    1. http://spotfired.blogspot.com/2016/10/trigger-script-when-clicking-on-tab.html

Remove an existing page

Description: Remove an existing page.
Assumptions: An optional 'myPage' page type script parameter.
Warning: Backup Spotfire files before removing pages.

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[3]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Remove an existing page
Application.Document.Pages.Remove(myPage) #Removes myPage
#Application.Document.Pages.RemoveAt(6)   #Removes the 7th page

Add a bar chart to a page

Description: Add a bar chart to a page.
Assumptions: An optional 'myPage' page type script parameter.

from Spotfire.Dxp.Application.Visuals import BarChart

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Add a chart to a page
myVis = myPage.Visuals.AddNew[BarChart]()
myVis.Data.DataTableReference = Document.Data.Tables["MyDataTable"]
myVis.Title = "New Bar Chart"

Show all visualizations on a page

Description: Show all visualizations on a specific page.
Assumptions: An optional 'myPage' page type script parameter.

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Loop through all visualizations on a page
for myVis in myPage.Visuals:
  print "Vis Name: " + myVis.Title
  print "Vis ID: " + myVis.Id.ToString()

Remove charts from a page

Description: Remove charts from a page.
Assumptions: An optional 'myPage' page type script parameter.
Warning: Backup Spotfire files before removing visualizations.

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Remove charts from a page
for myVis in myPage.Visuals:
  if (myVis.Title== "New Bar Chart"):
    myPage.Visuals.Remove(myVis)

Duplicate a page

Description: Duplicate an existing page.
Assumptions: An optional 'myPage' page type script parameter.

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Duplicate an existing page
Application.Document.Pages.AddDuplicate(myPage)

Switch active page

Description: Switch the active page.
Assumptions: An optional 'myPage' page type script parameter.

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Switch the visible page
Application.Document.ActivePageReference = myPage

Remove all bar chars from a page

Description: Remove all bar charts from a page.
Assumptions: An optional 'myPage' page type script parameter.
Warning: Backup Spotfire files before removing visualizations.

from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers

#Pick one of the following Page reference options:
#myPage = Application.Document.Pages[0]            #Page index method
#myPage = Application.Document.ActivePageReference #Active page method
#myPage as a page type script parameter            #Script parameter method

#Remove all bar charts from a page
for myVis in myPage.Visuals:
  if (myVis.TypeId == VisualTypeIdentifiers.BarChart):
    myPage.Visuals.Remove(myVis)

Add a page

Description: Add a new page. The new page will become the active page.

myPage = Application.Document.Pages.AddNew("My New Page") #AddNew(string) method
#myPage = Application.Document.Pages.AddNew()             #AddNew() method