IronPython crosstable to data script over rides Cross Table settings upon execution

Below script looks at two Cross Table visualizations and converts them to two seprate Data Tables. I then change these two Data Table to another set of Cross Tables to summarize on a higher level 

Issue is every time I run it, it over rides the later Cross Table settings. Also I see the script somehow by default converts a numeric column to string, I am looking for a way to keep the numeric column intact so that I don't have to update the data types every time I run the script.  

from System.IO import *
from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data.Import import TextFileDataSource
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Application.Visuals import TablePlot
from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers

#Export CrossTable data to the MemoryStream
mStream = MemoryStream();
mWriter = StreamWriter(mStream);

CrossTable1.As[CrossTablePlot]().ExportText(mWriter)

#Reset stream back to the beginning
mStream.Seek(0, SeekOrigin.Begin)

#Add cross table data back into Spotfire using TextFileDataSource
readerSet = TextDataReaderSettings()
readerSet.Separator = "\t"
readerSet.AddColumnNameRow(0)

textDataSource = TextFileDataSource(mStream, readerSet)

for table in Document.Data.Tables:
    if table.Name == "CrossTableData1":
        Document.Data.Tables.Remove(table.Name)

myNewTable = Document.Data.Tables.Add("CrossTableData1",textDataSource)

#If you want to change the data table to be embedded and not linked, use the following code
settings = DataTableSaveSettings (myNewTable,False, False);
Document.Data.SaveSettings.DataTableSettings.Add(settings);




#Export CrossTable data to the MemoryStream
mStream = MemoryStream();
mWriter = StreamWriter(mStream);

CrossTable2.As[CrossTablePlot]().ExportText(mWriter)

#Reset stream back to the beginning
mStream.Seek(0, SeekOrigin.Begin)

#Add cross table data back into Spotfire using TextFileDataSource
readerSet = TextDataReaderSettings()
readerSet.Separator = "\t"
readerSet.AddColumnNameRow(0)

textDataSource = TextFileDataSource(mStream, readerSet)

for table in Document.Data.Tables:
    if table.Name == "CrossTableData2":
        Document.Data.Tables.Remove(table.Name)

myNewTable = Document.Data.Tables.Add("CrossTableData2",textDataSource)

#If you want to change the data table to be embedded and not linked, use the following code
settings = DataTableSaveSettings (myNewTable,False, False);
Document.Data.SaveSettings.DataTableSettings.Add(settings);

 

(1) Answer

Login