Jump to content
  • Example Using IronPython with Spotfire Library Search API to Find DXP to Information Link Relationships


    This is an example of using the Library Search API in IronPython to load all of the DXPs in the Spotfire Library and find what Information Links they are dependent on. This should be fairly easy to tweak to support other use cases which could leverage the Library Search API. The IronPython code loads the various search results, coverts them into a data table so the data can be easily reviewed in Spotfire.

    This is an example of using the Library Search API in IronPython to load all of the DXPs in the Spotfire Library and find what Information Links they are dependent on. This should be fairly easy to tweak to support other use cases which could leverage the Library Search API. The IronPython code loads the various search results, coverts them into a data table so the data can be easily reviewed in Spotfire.

    The DXP is attached below.

    from System import Array,Guid,String,Object
    from Spotfire.Dxp.Framework.Library import LibraryManager, LibraryItemRetrievalOption, LibraryItemType, LibraryItem
    from Spotfire.Dxp.Data import AddRowsSettings
    from System.IO import  StreamWriter, MemoryStream, SeekOrigin
    from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
    from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings
    #
    libraryManager = Application.GetService[LibraryManager]()
    textData = "DXP,DXPCreated,DXPAccessed,DXPModified,Object,ObjType,ObjCreated,ObjAccessed,ObjModified\r\n"
    dxps = ""
    # Find All DXPs in the Library
    dxps = libraryManager.Search("type:dxp",LibraryItemRetrievalOption.IncludePath,LibraryItemRetrievalOption.IncludeProperties)
    if (dxps.Count > 0): 
       for dxp in dxps:
           # Find All Information Links required by a specific DXP
           searchStr="type:query required_by(item_id::"+dxp.Id.ToString()+")"
           objs= libraryManager.Search(searchStr,LibraryItemRetrievalOption.IncludePath)
           for obj in objs:
               textData+='"'+dxp.Path+'/'+dxp.Title+'","'+dxp.Created.ToString()+'","'+dxp.LastAccess.ToString()+'","'+dxp.LastModified.ToString()+'","'+obj.Path+'/'+obj.Title+'","query","'+obj.Created.ToString()+'","'+obj.LastAccess.ToString()+'","'+obj.LastModified.ToString()+'"\r\n'
           objs=''
    
    # Created Data Table based on search results
    loadData=1
    if (loadData):
      print 'Loading'
      stream = MemoryStream()
      writer = StreamWriter(stream)
      writer.Write(textData)
      writer.Flush()
      stream.Seek(0, SeekOrigin.Begin)
    
      readerSettings = TextDataReaderSettings()
      readerSettings.Separator = ","
      readerSettings.AddColumnNameRow(0) 
      readerSettings.SetDataType(0, DataType.String)
      readerSettings.SetDataType(1, DataType.String)
      readerSettings.SetDataType(2, DataType.String)
      readerSettings.SetDataType(3, DataType.String)
      readerSettings.SetDataType(4, DataType.String)
      readerSettings.SetDataType(5, DataType.String)
      readerSettings.SetDataType(6, DataType.String)
      textDataSource = TextFileDataSource(stream,readerSettings)
    
      settings = AddRowsSettings(Document.ActiveDataTableReference,textDataSource)
    
      Document.ActiveDataTableReference.ReplaceData(textDataSource)
    else:
      print textData
     

    Attachments

    You can download attachments from resources.

    search_library_ils_0.dxp


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...