繁体   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