Jump to content
  • IronPython script to save a file locally or to a library in Spotfire®


     

    Introduction

    Spotfire® allows users to save a DXP file to a local file or the Spotfire library. This script allows saving of the file to be automated.

    Save As

    The below script can be used to save a data table to a local file/library. The save as operation is a transaction. That means it must be run on the Application thread once the main script has completed execution. This script is interesting because it shows an example of how to execute code on the Application thread.

    This method of saving a file using the Application thread is not strictly necessary if you are using Spotfire 7.6 and above - you can uncheck the "Execute in a transaction" checkbox on the script editor in order that the save as operation will complete within the script execution itself. However, this example is shown for completeness as there may be other instances where executing code on the Application thread is useful.

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    # Import namespaces
    from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread
    from Spotfire.Dxp.Application import DocumentSaveSettings
    from Spotfire.Dxp.Framework.Library import *
    
    # Declaring the function which will run async
    def saveAsLibraryItem(app, folder, fileName, metaData, saveSettings):
       def f():
          app.SaveAs(folder, fileName, metaData, saveSettings)
       return f
    
    # save local
    def saveAsLocal(app, folderName, fileName, saveSettings):
    	def f():
    		fullPath = folderName + fileName
    		app.SaveAs(fullPath, saveSettings)
    	return f
    
    
    # Set the folder path and file name for a local file
    folderName = "c:\\"
    fileName = "Test File.dxp"
    
    # Save as library item
    folderName = "/Spotfire Test Folder/Reports"
    fileName = "Test File"
    # Set up the LibraryManager and ensure that we can 
    # access the folder path specified
    libraryManager = Document.GetService(LibraryManager)
    success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder)
    
    # Executing the function on the application thread, and Save the document back to the Library
    
    Application.GetService[ApplicationThread]().InvokeAsynchronously(saveAsLibraryItem(Application, libraryFolder, fileName, LibraryItemMetadataSettings(), DocumentSaveSettings()))
    
    # Save as local file
    Application.GetService[ApplicationThread]().InvokeAsynchronously(saveAsLocal(Application, folderName, fileName, DocumentSaveSettings()))
     

     

    License:  TIBCO BSD-Style License

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...