我正在尝试使用ironpython脚本将文档另存为'onPropertyChange'事件上的库项目。 附加到该属性的脚本代码:
# 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”无效答案 0 :(得分:2)
显然,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运行事务中的代码。”