使用 ironPython 的 Spotfire 另存为
Spotfire SaveAs using ironPython
我正在尝试使用 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())
不幸的是,我收到以下错误:
在状态 'Executing'
中对命令历史的无效操作 '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 的回答:
"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."
我正在尝试使用 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())
不幸的是,我收到以下错误:
在状态 'Executing'
中对命令历史的无效操作 '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 的回答:
"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."