简体   繁体   English

使用ironPython进行Spotfire另存为

[英]Spotfire SaveAs using ironPython

I am trying to SaveAs a document as a library item on 'onPropertyChange' event using ironpython script. 我正在尝试使用ironpython脚本在'onPropertyChange'事件中将SaveAs文档另存为库项。 the script`s code attached to the property : 附加到该属性的脚本代码:

# 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())

Unfortunately, I get the following error : 不幸的是,我收到以下错误:

Invalid operation 'BeginAggregatedTransaction' to the command history when in state 'Executing' 处于“执行”状态时,对命令历史记录的操作“ BeginAggregatedTransaction”无效

  • Is there a problem with the script ? 脚本有问题吗? in case not , is there a way to save as a library item using a script or an api function (via javascript or ironpython)? 如果没有,有没有办法使用脚本或api函数(通过javascript或ironpython)另存为库项?

Apparently all ironpython scripts in spotfire run in transactions, and some api functions, such as 'SaveAs' are trying to invoke a second transaction, which causes the script to fail. 显然,spotfire中的所有ironpython脚本都在事务中运行,并且某些api函数(例如“ SaveAs”)正在尝试调用第二个事务,这会导致脚本失败。

therefore, the 'SaveAs' function call should run on the application thread, and thereby get outside the transaction. 因此,“ SaveAs”函数调用应在应用程序线程上运行,从而脱离事务。

the final code which works : 起作用的最终代码:

# 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()))

according to Tibco`s answer : 根据Tibco的回答:

"Hopefully when Spotfire 7.5 is released we will have a more permanent solution to these types of issues since we can then select not to run the code inside a transaction from the UI." “希望在发布Spotfire 7.5时,我们将针对这些类型的问题提供更永久的解决方案,因为我们可以选择不从UI内在事务内运行代码。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM