Back to main IronPython scripting page
Introduction
This article shows a sample script on how to cleanly swap a data table in a DXP with a SBDF from the Library without breaking Column references.
Code Sample
# Copyright © 2020. TIBCO Software Inc. Licensed under TIBCO BSD-style license. #Andrew Berridge, Neil Kanungo - TIBCO Software from Spotfire.Dxp.Data import * from Spotfire.Dxp.Framework.Library import * from Spotfire.Dxp.Framework.ApplicationModel import * from Spotfire.Dxp.Data.Import import * import clr from System import Array lm = Application.GetService[LibraryManager]() li = clr.Reference[LibraryItem]() def tableCloth(dataTableName, pathToSBDF): print lm.TryGetItem(pathToSBDF, LibraryItemType.SbdfDataFile, li, Array.CreateInstance(LibraryItemRetrievalOption,0)) ds = SbdfLibraryDataSource(li.Value) dt = Document.Data.Tables[dataTableName] removeCalculatedColumns = False # Set this to true if you are replacing calculated columns with imported columns removeResultColumns = True # Set this to false to leave result columns alone columnsToLeaveAlone = "ActiveDAys"; # Add any columns here that you want to exclude from ripping out - i.e. those that you are not replacing # Remove result columns and/or calculated columns - these columns should be present in the underlying SBDF and the names must # match the existing result/calculated column names colsToRemove = [] for c in dt.Columns: print c.Name print c.Properties.ColumnType if not columnsToLeaveAlone.contains(c.Name): if c.Properties.ColumnType == DataColumnType.Result and removeResultColumns: colsToRemove.append(c) if c.Properties.ColumnType == DataColumnType.Calculated and removeCalculatedColumns: colsToRemove.append(c) for c in colsToRemove: dt.Columns.Remove(c) dt.ReplaceData(ds) tableCloth("[YOUR DAT TABLE NAME HERE]", "[YOUR LIBRARY SBDF PATH HERE]")
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.