Jump to content
  • How to use IronPython in Spotfire® to get the dataTable source information


    This example illustrates how to find the source information for all the different data tables sources available in Spotfire like information links,connectors,text files etc.

    Introduction

    This example illustrates how to find the source information for all the different data tables sources available in Spotfire like information links,connectors,text files etc.

    Attached is a dxp for reference.

    Code sample

    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+"<tr><td>"+tableName+"</td><td>"+type+"</td><td>"+path+"</td></tr>"
    
    html="<table border=1><tr style='text-align:center'><th>Data Table</th><th>Type</th><th>Source</th></tr>"
    
    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+"</table>"
     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.
     

     

    References

     

    License:  TIBCO BSD-Style License

    sourceinformation_all_tables.dxp


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...