mike.mcgarvey Posted November 20 Posted November 20 This feels like it should be a simple task, but I keep going in error circles with Copilot trying to create an IronPython script to handle this. I want to make this pared down table so that I can add just those rows to a third table. Here is the script I'm starting with that is failing. It seems to fail when I call out "Marking". It seemed to work when using Document.ActiveMarkingSelectionReference, but the resulting table didn't match what was marked so I wanted to call out specifically the name of the marking I'm using. Any help would be greatly appreciated. from Spotfire.Dxp.Data import DataFlowBuilder from Spotfire.Dxp.Data.Import import DataTableDataSource from Spotfire.Dxp.Data import * # Source table name tableName = "table1" dt = Document.Data.Tables[tableName] # Use specific marking called "Marking" marking = Document.Data.Markings["Marking"] dataSelection = marking.GetSelection(dt) ds = DataTableDataSource(Document.Data.Tables[tableName], dataSelection) dfb = DataFlowBuilder(ds, Application.ImportContext) context = Document flow = dfb.Build() # Overwrite "MarkedLRP" table if it exists if "MarkedLRP" in Document.Data.Tables: Document.Data.Tables.Remove("Markedtable1") # Add data table Document.Data.Tables.Add("Markedtable1", flow)
Solution mike.mcgarvey Posted November 20 Author Solution Posted November 20 Of course, I figure it out almost as soon as I post it. Below is the working script. from Spotfire.Dxp.Data import DataFlowBuilder from Spotfire.Dxp.Data.Import import DataTableDataSource from Spotfire.Dxp.Data import RowSelection, IndexSet # Source tableName = "table1" dt = Document.Data.Tables[tableName] markings = Document.Data.Markings["Marking"] # Filter columns ds = DataTableDataSource(Document.Data.Tables[tableName], markings) dfb = DataFlowBuilder(ds, Application.ImportContext) context = Document flow = dfb.Build() # All columns are imported, and only marked rows: try: # if the table already exists filtered_table = Document.Data.Tables["Markedtable1"] filtered_table.ReplaceData(ds) except: # if the table was not created before Document.Data.Tables.Add("Markedtable1", flow) 2
barchiel33 Posted November 20 Posted November 20 I would actually suggest using a Python data function instead of an Ironpython script. For your use case, it would take less scripting and, I believe, would be faster as well. The script could literally be this simple: The Input Parameter would be inputTable, which is a table type parameter. The Output Parameter would be outputTable, which would also be a table type parameter. When you set the input parameter when you actually run the function, you can specify a filter scheme and a marking (or markings) to use. Then you can output to a new table (future runs of the function will automatically default to over-writing that table, so it won't just keep creating new tables). Also, you can select the Refresh function automatically and that will cause it to run whenever the marking changes, so you could have a user select rows and it'll automatically move that marked data to the specified table. The only issue I can see is if no rows are marked when the function runs, since it can't really handle columns made entirely of null values, I can't remember what the workaround to that is off the top of my head, maybe someone else knows. I'd imagine the Ironpython script would have a similar issue. 1
mike.mcgarvey Posted November 20 Author Posted November 20 Thank you, barchiel33! That's a much better solution than the IronPython script! Much cleaner and great that it updates automatically. Already incorporated it and it works great! 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now