I keep getting this error, "Cannot access protected member GetService without a python subclass of Document" on this line of code ... "progressService = Document.GetService(ProgressService)"
The code below is meant to prompt a save as dialog and save a file to a folder in a certain location.
Here is the code:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import
MessageBox,Form,MessageBoxButtons,DialogResult
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *
from Spotfire.Dxp.Framework.ApplicationModel import ProgressService
message="Would you like to save the file"
caption="Save to Library"
reply=MessageBox.Show(message,caption,MessageBoxButtons.YesNo)
def savetoLibrary():
folderName = r"C:\Users\Documents\NEW"
fileName = "TESTNEW.xlsx"
libraryManager = Document.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder)
settings = DocumentSaveSettings()
Application.SaveAs(libraryFolder,fileName,LibraryItemMetadataSettings(), settings);
if reply==DialogResult.Yes:
progressService = Document.GetService(ProgressService)
progressService.ExecuteWithProgress("Saving to Library", "Saving analysis", savetoLibrary)
Set up the Library Manager and ensure that we can access the folder path specified
The GetService for ProgressService and LibraryManager is on the Application instead of the Document. This should work for you, assuming your library is set up on a filesystem instead of the Spotfire database.
If you have the Spotfire Library stored in the Spotfire database, your foldername and filename will look more like '/spotfire/library/path' and 'filename' respectively.
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox,Form,MessageBoxButtons,DialogResult
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *
from Spotfire.Dxp.Framework.ApplicationModel import ProgressService
message="Would you like to save the file"
caption="Save to Library"
reply=MessageBox.Show(message,caption,MessageBoxButtons.YesNo)
def savetoLibrary():
folderName = r"C:\Users\Documents\NEW"
fileName = "TESTNEW.xlsx"
libraryManager = Application.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(spotfireLibraryFolder, LibraryItemType.Folder)
settings = DocumentSaveSettings()
Application.SaveAs(libraryFolder,fileName,LibraryItemMetadataSettings(), settings);
if reply==DialogResult.Yes:
progressService = Application.GetService(ProgressService)
progressService.ExecuteWithProgress("Saving to Library", "Saving analysis", savetoLibrary)