Labels

Mark rows

1
2
3
4
5
6
7
from Spotfire.Dxp.Application.Visuals import TablePlot

targetViz = markingViz.As[TablePlot]();

rowSelection = targetViz.Data.DataTableReference.Select(selectStatement);

targetViz.Data.MarkingReference.SetSelection(rowSelection, targetViz.Data.DataTableReference);

Input:
markingViz (Table): A visualization that current has the marking profile applied.
selectStatement (String): A query-like string that indicates what records should me marked.  For example:

columnname > 2

This script can be modified to work with any visualization type.


Sort a table visualization

1
2
3
4
5
6
from Spotfire.Dxp.Application.Visuals import TablePlot, TablePlotColumnSortMode

toTableSort = vTable.As[TablePlot]();
todataColumn = toTableSort.Data.DataTableReference.Columns[sortColumn];
toTableSort.SortInfos.Clear();
toTableSort.SortInfos.Add(todataColumn, TablePlotColumnSortMode.Ascending);

Input:
sortColumn (String): The column name of the column to sort
vTable (Table): The target table visualization


Export a table visualization to a file


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot
 
#Temp file for storing the table data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

#Export table data to the temp file
writer = StreamWriter(tempFilename)
vTable.As[TablePlot]().ExportText(writer)

print tempFilename

Input
vTable (Visualization)

Not suitable for use over the web since the local file system is used.

Change filter panel search criteria

1
2
3
4
5
page = Application.Document.ActivePageReference

filterPanel = page.FilterPanel

filterPanel.InteractiveSearchPattern = "status:modified"

This script is used to set the search criteria in the filter panel.  This can be used to selectively display only certain filters.  It's possible to search the filters based on the column properties, for example:

datatype:string
externalname:ag*
columntype:imported


Show current filter settings


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from Spotfire.Dxp.Application.Visuals import VisualContent
from System import Guid

page = Application.Document.ActivePageReference

#Get the filtering scheme used on this page
filteringSchemeRef = page.FilterPanel.FilteringSchemeReference

#Get the name of the filtering scheme on the active page
for filteringScheme in Document.FilteringSchemes:
 filteringSelection = filteringScheme.FilteringSelectionReference
 if filteringScheme == filteringSchemeRef: 
  filteringSchemeName = filteringSelection.Name

content="<STRONG>Filtering Scheme:</STRONG> " + filteringSchemeName

filterPanel = page.FilterPanel
filterPanel.InteractiveSearchPattern = "status:m"

for filters in filterPanel.FiltersMatchingSearchPattern:
 print filters.FilterReference.ToString()

for tableGroup in filterPanel.TableGroups :
 print tableGroup.ToString()
 tableGroup.Expanded=True
 for filterGroup in tableGroup.SubGroups :
  print filterGroup.ToString()
  print filterGroup.Expanded
  filterGroup.Visible=False
  if (filterGroup.Expanded == False):
      filterGroup.Expanded = True
  else:
   filterGroup.Expanded = False

for tableGroup in filterPanel.TableGroups:
 isMod=0
 str="<p>"
 if filterPanel.TableGroups.Count > 1:
  str+="<b>"+tableGroup.FilterCollectionReference.DataTableReference.Name+":</b><br>"
 for fh in tableGroup.FilterHandles:
  if fh.FilterReference.Modified:
   isMod=-1
   str+=fh.FilterReference.ToString()
   str+="<br>"
 for subGroup in tableGroup.SubGroups:
  for fh in subGroup.FilterHandles:
   if fh.FilterReference.Modified:
    isMod=-1
    str+=fh.FilterReference.ToString()
    str+="<br>"
 str+="</p>"
 if isMod==-1:
  content+=str  

ta=vTextArea.As[VisualContent]()
if(ta.HtmlContent is None):
 ta.HtmlContent = " "

if (ta.HtmlContent.find("<SPAN id=fs>")==-1):
  ta.HtmlContent=="<SPAN id=fs>"+ta.HtmlContent
final=ta.HtmlContent.split("<SPAN id=fs>")[0]+"<SPAN id=fs>"+content+"</SPAN>"
ta.HtmlContent=final

#Reset filter panel search and navigate to the Filter Settings Page
filterPanel.InteractiveSearchPattern = ""

Input:
vTextArea (Text Area): The text area that will be modified to show the current filter settings.

This script will list the modified filters for the current page, and how they have been modified.  The output will be generated in HTML format and inserted into the specified text area.  Here is a sample of the output:



Here is a similar variation that also is compatible with in-database connections:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from Spotfire.Dxp.Application.Visuals import VisualContent
from System import Guid

page = Application.Document.ActivePageReference


#Get the filtering scheme used on this page
filteringSchemeRef = page.FilterPanel.FilteringSchemeReference

filterPanel = page.FilterPanel

#Now set the filtering scheme to that of the originating page
filterPanel.FilteringSchemeReference = filteringSchemeRef

for filteringScheme in Document.FilteringSchemes:
 filteringSelection = filteringScheme.FilteringSelectionReference
 if filteringScheme == filteringSchemeRef: 
  filteringSchemeName = filteringSelection.Name

content="<STRONG>Filtering Scheme:</STRONG> " + filteringSchemeName + "<BR><BR>"

filterPanel.InteractiveSearchPattern = "status:m"
for filters in filterPanel.FiltersMatchingSearchPattern:
 content += filters.FilterReference.ToString() + "<BR>"


ta=vTextArea.As[VisualContent]()
if(ta.HtmlContent is None):
 ta.HtmlContent = " "

if (ta.HtmlContent.find("<SPAN id=fs>")==-1):
  ta.HtmlContent=="<SPAN id=fs>"+ta.HtmlContent
final=ta.HtmlContent.split("<SPAN id=fs>")[0]+"<SPAN id=fs>"+content+"</SPAN>"
ta.HtmlContent=final

filterPanel.InteractiveSearchPattern = ""

Change the page

1
Document.ActivePageReference = Document.Pages[2]

Page index starts at 0.

Change the URL of the Collaboration Panel

1
2
3
4
5
6
7
8
9
import clr
clr.AddReference ( "System" )
import System
from System import Uri
import Spotfire.Dxp.Application

for panel in Application.Document.ActivePageReference.Panels:
 if panel.Title == "Collaboration":
  panel.Url = Uri ( "http://www.google.com" )

This script will change the URL of the Collaboration Panel for the active page.

Perform operations on the columns in a Graphical Table

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from Spotfire.Dxp.Application.Visuals.Miniatures import GraphicalTable
from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers

for col in gtable.As[GraphicalTable]().Columns: 
 #Calculated Value Columns
 if col.Visualization.TypeId == VisualTypeIdentifiers.CalculatedValueMiniatureVisualization:
  try:
   vExp = col.Visualization.ValueAxis.Expression
  except:
   0

 #Icon Columns
 if col.Visualization.TypeId == VisualTypeIdentifiers.IconMiniatureVisualization:
  try:   
   vExp = col.Visualization.IconAxis.Expression
  except:
   0

 #Sparkline Columns
 if col.Visualization.TypeId == VisualTypeIdentifiers.SparklineMiniatureVisualization:
  try:   
   vExp = col.Visualization.YAxis.Expression
  except:
   0

 #Bullet Graph Columns
 if col.Visualization.TypeId == VisualTypeIdentifiers.BulletGraphMiniatureVisualization:
  try:   
   vExp = col.Visualization.ValueAxis.Expression
  except:
   0

 try:
  col.Title = vExp
 except:
  0

Input:
gtable (Graphical Table)

This script will loop over the columns in a Graphical Table, find the expression used, and set the column title to display the expression.


Loop through all visualizations on a page

1
2
for p in page.Visuals:
 print p.Title

Input: 
page (Page)

Toggle the details-on-demand panel on\off

1
2
3
4
if (Document.ActivePageReference.DetailsOnDemandPanel.Visible == False):
   Document.ActivePageReference.DetailsOnDemandPanel.Visible = True
else:
   Document.ActivePageReference.DetailsOnDemandPanel.Visible = False

Toggle the filter panel on\off

1
2
3
4
if (Document.ActivePageReference.FilterPanel.Visible == False):
   Document.ActivePageReference.FilterPanel.Visible = True
else:
   Document.ActivePageReference.FilterPanel.Visible = False

Change the datatable of a table visualization

1
2
3
4
5
6
7
from Spotfire.Dxp.Application.Visuals import VisualContent

tbl = currentTableVisualization.As[VisualContent]()
newtbl = Document.Data.Tables.Item[newDataTableName]
tbl.Data.DataTableReference=newtbl
tbl.AutoConfigure()
tbl.ApplyUserPreferences()

Input:
currentTableVisualization (Visualization): The table visualization that will have its datatable changed.
newDataTableName (String): The name of the new datatable.


Clear marking (unmark)

1
2
3
4
5
6
7
from Spotfire.Dxp.Data import DataManager 
from Spotfire.Dxp.Data import IndexSet 
from Spotfire.Dxp.Data import RowSelection 

marking=Application.GetService[DataManager]().Markings[markingName]
selectRows = IndexSet(dataTable.RowCount, False)
marking.SetSelection(RowSelection(selectRows),dataTable)

Input:
markingName (String): The name of the marking profile to clear.
dataTable (Data Table): The data table that currently has the marking applied.

Refresh a stale data table

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

Input: table (Data Table)

This script is equivalent to pressing the red "refresh" icon that is shown when the data table is stale.

Get the current user's username

1
2
from System.Threading import Thread 
print Thread.CurrentPrincipal.Identity.Name 

Create a document property and set its value

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from Spotfire.Dxp.Data import DataProperty 
from Spotfire.Dxp.Data import DataType 
from Spotfire.Dxp.Data import DataPropertyClass 

propName  = "myDocumentProperty2" 
attr   = DataProperty.DefaultAttributes 
prop   = DataProperty.CreateCustomPrototype(propName, DataType.String, attr) 

Document.Data.Properties.AddProperty(DataPropertyClass.Document, prop) 

prop.Value  = "myDocumentPropertyValue"

Loop through all pages

1
2
for page in Application.Document.Pages:
 print page.Title

Set a document property

1
Document.Properties['property name'] = 'hello'