簡體   English   中英

使用ironPython進行Spotfire另存為

[英]Spotfire SaveAs using ironPython

我正在嘗試使用ironpython腳本在'onPropertyChange'事件中將SaveAs文檔另存為庫項。 附加到該屬性的腳本代碼:

# Import namespaces
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *

# Set the folder path and file name
folderName = "/Spotfire Test Folder/Reports"
fileName = "Test File"

# Set up the LibraryMangager and ensure that we can 
# access the folder path specified
libraryManager = Document.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder)

# Embed the data
Document.Data.SaveSettings.EmbedAllSourceData = 1

# Save the document back to the Library
Application.SaveAs(libraryFolder, fileName, LibraryItemMetadataSettings(), DocumentSaveSettings())

不幸的是,我收到以下錯誤:

處於“執行”狀態時,對命令歷史記錄的操作“ BeginAggregatedTransaction”無效

  • 腳本有問題嗎? 如果沒有,有沒有辦法使用腳本或api函數(通過javascript或ironpython)另存為庫項?

顯然,spotfire中的所有ironpython腳本都在事務中運行,並且某些api函數(例如“ SaveAs”)正在嘗試調用第二個事務,這會導致腳本失敗。

因此,“ SaveAs”函數調用應在應用程序線程上運行,從而脫離事務。

起作用的最終代碼:

# 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 g(app, folder, fileName, metaData, saveSettings):
   def f():
      app.SaveAs(folder, fileName, metaData, saveSettings)
   return f

# Set the folder path and file name
folderName = "/Spotfire Test Folder/Reports"
fileName = "Test File"

# Set up the LibraryMangager 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(g(Application, libraryFolder, fileName, LibraryItemMetadataSettings(), DocumentSaveSettings()))

根據Tibco的回答:

“希望在發布Spotfire 7.5時,我們將針對這些類型的問題提供更永久的解決方案,因為我們可以選擇不從UI內在事務內運行代碼。”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM