all datatables in iron pyython code example

Example: all datatables in iron pyython

from Spotfire.Dxp.Data.DataOperations import DataSourceOperation
from Spotfire.Dxp.Application import DocumentMetadata
from Spotfire.Dxp.Data.DataOperations import DataOperation
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
from Spotfire.Dxp.Framework.Library import LibraryManager, LibraryItemType, LibraryItem, LibraryItemRetrievalOption
lm = Application.GetService(LibraryManager)
from System import Guid

#Function to write the tablename, its type and location in an html table for readability.
def writeHtml(tableName,type,path):
 global html
 html=html+""+tableName+""+type+""+path+""

html=""

for tbl in Document.Data.Tables:
 sourceView = tbl.GenerateSourceView();
 op=sourceView.GetAllOperations[DataOperation]()

 #DataSourceOperation corresponds to tables created via copying content from Clipboard,Informationlinks,Text Files & SBDF/STDF files
 if type(op[0]).__name__ == 'DataSourceOperation':
  t=op[0].GetDataFlow().DataSource
  if(type(t).__name__  == "InformationLinkDataSource"):
   found=t.FindAll("id::"+str(t.Id))
   writeHtml(tbl.Name,type(t).__name__,found.First.Path)
  if(type(t).__name__  == "TextFileDataSource" or type(t).__name__  == "Excel2FileDataSource"):
   if (t.FilePath == None):
    path="Clipboard"
   else:
    path=t.FilePath
   writeHtml(tbl.Name,type(t).__name__,path)
  if(type(t).__name__ == "DatabaseDataSource"):
    writeHtml(tbl.Name,type(t).__name__,t.Settings.Provider)
  if(type(t).__name__  == "StdfFileDataSource" or type(t).__name__  == "SbdfFileDataSource"):
    writeHtml(tbl.Name,type(t).__name__,t.FilePath)
  if(type(t).__name__  == "SbdfLibraryDataSource"):
   l = lm.Search(t.Name, LibraryItemRetrievalOption.IncludePath)
   for item in l:
    writeHtml(tbl.Name,type(t).__name__,item.Path)

 #DataConnectionOperation corresponds to using data connections (connectors)
 elif(type(op[0]).__name__ == "DataConnectionOperation"):
   writeHtml(tbl.Name,type(op[0]).__name__,op[0].DisplayName)

 #DataTableDataSourceOperation corresponds to datatables added using existing tables
 elif(type(op[0]).__name__ == "DataTableDataSourceOperation"):
   writeHtml(tbl.Name,type(op[0]).__name__,op[0].DataTable.Name)

 #DataFunctionOperation corresponds to datatable added via Data Function
 elif (type(op[0]).__name__ == "DataFunctionOperation"):  
  t=op[0].DataFunction   
  sourceType= t.DataFunctionDefinition.ServiceType.DisplayName   
  writeHtml(tbl.Name,sourceType,op[0].DisplayName)
 
 html=html+"
Data TableTypeSource
" myTextArea.As[HtmlTextArea]().HtmlContent=html myTextArea - script parameter referring to a Textarea visualization which will be populated with the source information for all the data tables in the current dxp.

Tags:

Misc Example