Luke George 2 Posted July 18, 2019 Share Posted July 18, 2019 I'm looking for a way to replace the data table in spotfire using a property control and Iron python script. I found some other scripts to do this, but they bring up a dialog box to select the replacement data table. I would like to do this without a dialog box selection. I would like the property control to be a drop down list of fixed values where the fixed values match table names in a folder. Upon selecting any filename in the drop down list, the corresponding table automatically replaces the existing data table. Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted July 18, 2019 Share Posted July 18, 2019 You can use below sample script as a reference and make changes to the document property , data table name and specify the folder path from Spotfire.Dxp.Data import * #read the file name from drop down fileName=Document.Properties["fileName"] #If need to specify any settings for the file readerSettings = TextDataReaderSettings() #create a datasource dSource = TextFileDataSource(r"c:\filepath\"+fileName,readerSettings) #replace datatable Document.Data.Tables["myTableName"].ReplaceData(dSource) Link to comment Share on other sites More sharing options...
Luke George 2 Posted July 19, 2019 Author Share Posted July 19, 2019 Hi Shandilya,Thankyou for your help. I have implemented the code: from Spotfire.Dxp.Data import * #read the file name from drop down fileName=Document.Properties["Property1"] #If need to specify any settings for the file readerSettings = TextDataReaderSettings() #create a datasource dSource = TextFileDataSource(r"D:\FolderDATA\"+fileName,readerSettings) #replace datatable Document.Data.Tables["Analysis"].ReplaceData(dSource)But I get an error:NameError: name 'TextDataReaderSettings' is not definedI assume this is because I have nothing in TextDataReaderSettings(), but I have no specific settings for the files I'm loading. They are all csv files that are identically formatted. How should I adjust the scriptThankyou Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted July 19, 2019 Share Posted July 19, 2019 you should include the following namspace in your code, from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings Link to comment Share on other sites More sharing options...
Luke George 2 Posted July 22, 2019 Author Share Posted July 22, 2019 Hi Shandilya, Thank you for your help again. I added "from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings" and I no longer get the error, however it now says "Exception: File not found: D:\FolderDATA\File1" even though File1 is in the folder. I changed the file name to fileName=Document.Properties["DrillholeSelection"]+".txt" and the code seems to work now. The only problem is the entire document gets loaded as a single column even though the spreadsheet has over 50 columns... And idea how to fix this Thank you Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted July 22, 2019 Share Posted July 22, 2019 How is the data separated in the text file, based on the separator you may want to specify it. For example if the data is separated by comma, then use settings=TextDataReaderSettings() settings.Separator="," Link to comment Share on other sites More sharing options...
Luke George 2 Posted July 23, 2019 Author Share Posted July 23, 2019 Hi Shandilya, I made the changes you suggested and it works now! I also had to specify the name row and data type for each column. Thanks for all your help :) Link to comment Share on other sites More sharing options...
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