【问题标题】:Spotfire SaveAs using ironPython使用 IronPython 的 Spotfire SaveAs
【发布时间】:2015-12-27 12:45:13
【问题描述】:

我正在尝试使用 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”操作无效

  • 脚本有问题吗?如果没有,有没有办法使用脚本或 api 函数(通过 javascript 或 ironpython)保存为库项目?

【问题讨论】:

  • 网页播放器的行为与胖客户端中的行为相同吗?
  • 是的,它抛出了同样的异常。

标签: ironpython spotfire


【解决方案1】:

显然,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 中的事务内运行代码。”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    相关资源
    最近更新 更多