01-29-2009 08:10 AM
Does anyone know of a way to import .csv files programatically with an .STP file without opening the import dialog box everytime?
I've been through the forum and seen solutions for .xls files, and through the help file that recommends using the ExcelImport command, but these don't seem to work for .csv file types. I currently am using the DataFileLoad command to import the files, which works fine to load the .csv files, but it requires me to browse to the .STP file for each file.
Does anyone know a more efficient way to import a .csv file programatically?
Solved! Go to Solution.
01-30-2009 02:22 PM
Hi Steve,
Would you be willing to post one of your CSV files to this Discussion Forum or send it to my email? Your best option is going to be a DataPlugin. It is possible to import via STP file without a dialog, but 'd prefer to set you up with the superior DataPLugin solution.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-30-2009 02:36 PM
Thanks for your response. Here is a sample CSV file and the STP file that I'm using to import the data.
EDIT: I tried posting the STP file, but the forum blocked that file type. I can email it if you need it.
02-02-2009 09:44 AM
Hi Steve,
I created a 25 line DataPlugin that reads your ASCII data files with the *.XLS file extension. The DataPlugin checks to see if there is a "Time stamp" text in the first 20 characters of the data file and errors out if it doesn't find them. This will exclude Excel files with the *.XLS file extension as well as any other ASCII files with the *.XLS file extension that are not of this same ASCII file format.
Because of the "PM" suffix at the end of your date/time strings, this DataPlugin will only work properly in DIAdem 10.1 or later. I could send you a version of the DataPlugin that will run on DIAdem 9.1 or 10.0, but it would completely ignore the "AM/PM" suffix. If you have a DIAdem version prior to 9.1, then I will happily send you the code lines you originally asked for.
Just download this ZIP file, unzip it anywhere on your hard drive, then double-click on the *.URI file within (using Windows Explorer) to register the DataPlugin. Thereafter you will be able to drag&drop your *.XLS files directly from the NAVIGATOR to the Data Portal, and the DataFinder will also be able to index the contents of thes ASCII data files.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
02-04-2009 08:47 AM
Brad,
I don't have a problem importing the *.XLS files, it's the *.CSV files that are the problem. When I import the files, I use the STP file to get rid of all of the time columns and keep only the signals with "(VDC)" in the column name. I regenerate a generic time channel in DiAdem and convert to waveforms because I usually get errors about data not being equidistant.
So basically what I want to happen is to import a group of CSV files, Pull out only a few of the columns of (VDC) data that I'm interested in in each file, then convert to waveforms and prepare everything for analysis without having to point to the STP file for every file that opens in the loop.
I'm including my entire script so that you can get a better understanding of what I'm trying to do.
Steve
02-05-2009 02:15 PM
Hi Steve,
Sorry, when I downloaded your posted file from the Discussion Forum, it got automatically renamed with a *.xls file extension instead of *.csv-- I suppose some layer of software thought this was being helpful, but I didn't notice this change. I assumed you had posted an ASCII file with an *.xls file extension (which is more common than you might expect) and that somehow the link name and the file behind the link had gotten out of sync.
Anyway, here is a new version of the DataPlugin that imports *.csv files instead of ASCII files with the file extension *.xls. Based on your subsequent comments and the contents of the analysis VBScript you posted, I made a few changes to the DataPlugin this time. Now it automatically exposes all the non-time channels as waveform channels and automatically ignores the time channels during import. It takes the delta time value from the first two values of each XXX(Seconds) channel, respectively, rounded to the nearest integer (second). If no XXX(Seconds) channel is found in the file at all, it defaults to 2 seconds for the standard interval. I chose to make the initial time = 0 in all cases. I also exposed the suffix of the channel name as that channel's unit string, which you can see in the "Unit" property in the Data Portal. We could easily automatically remove that suffix from the imported channel name.
Once you've registered this DataPlugin, you can use it in DIAdem by just dragging and dropping one of these *.csv files from the NAVIGATOR into the Data Portal. You can do the same thing programmatically with the command:
Call DataFileLoad("C:\SampleCSV.csv", "SteveKoza_CSV")
If you want to only load some data channels, you can use a variant of this command:
Call DataFileLoadSel(AutoActPath & "SampleCSV.csv", "SteveKoza_CSV", "[1]/101(VDC)")
Call DataFileLoadSel(AutoActPath & "SampleCSV.csv", "SteveKoza_CSV", "[1]/[1,2]")
Brad
02-06-2009 07:56 AM
Wow......That took a fraction of the time that the Dialog Box method did. I'm going to have to review the Data Plugin portion of my DiAdem Advanced manual.
Thanks, Brad!
Steve