DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Multiple TDMS files to Excel

Hi All,

 

I am trying to convert multiple TDMS files to an Excel format with a reduced sample rate. The TDMS files are sampled at 25kHz and I would like the Excel files to be 2.5 kHz.

 

I can do this manually for each file by loading the TDMS file, using the script below, deleting the original group and resaving the file as an Excel. Here is the script:

 

Call GroupCreate("Reduced Channels")
Call GroupDefaultSet(GroupCount)
ReducVal = 10 'Reduction value (total reduction = original/this value.
CalcXChn = 1 'Time base channel.
CalcYChn = "2-6" 'Channels in group to be reduced.
ClassNo = ChnLength(CalcXChn)\ReducVal
Call ChnClassXRedXY(CalcXChn, CalcXChn, CalcYChn, "Automatic", "Mean")
FOR i = 1 TO GroupChnCount(GroupCount)
  ChnName(CNoXGet(GroupCount, i)) = ChnName(CNoXGet(1, i))
Next

 

Ideally, I would like to have a user interface which allows the user to select the file(s) and have a program to reduce the sample rate and save it as an Excel File. Unfortunately, this I have not been able to acheive yet.

 

I have attached an Excel file that has been converted manually. Any help would be appreciated.

 

Thanks

 

 

0 Kudos
Message 1 of 10
(7,461 Views)

Hello,

 

Deleting the original group and saving the file as an Excel File could be automated. You can also use the FileDlgShow command to allow users to select multiple files from a dialog box, then run your script on each file in turn. Adding these steps should help streamline the process.

Steven Gloor
Staff Customer Engineer - CTA, CLD
0 Kudos
Message 2 of 10
(7,404 Views)

Thanks Steven,

 

I will give this a try.

0 Kudos
Message 3 of 10
(7,386 Views)

OK,

 

Instead of converting to an Excel file, I would be satisfied with converting to a .CSV file.

 

I created a new script to convert the filelist to CSV, but I am not sure how to use the original file names (just replacing the .TDMS extension with the .CSV extension).

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.
Dim i
If FileDlgShow(DataReadPath,"TDM Files,*.tdm","DataSelection",True) = "IDOk" Then
For i = 0 to UBound(FileDlgNameList)
Call Data.Root.Clear()
Call DataFileLoad(FileDlgNameList(i),"TDM","Load")
Call DataFileSave(FileDlgNameList(i),"CSV")
Next
End If

 

In particular, the statement "Call DataFileSave(FileDlgNameList(i),"CSV")" needs to do this I assume, but I am not sure about the syntax.

 

Thanks for the help.

0 Kudos
Message 4 of 10
(7,359 Views)

Hi CVfactor,

 

Here's the code to use the folders and file name but not the file extension:

 

CsvFilePath = NameSplit(FileDlgNameList(i), "P") & NameSplit(FileDlgNameList(i), "N") & ".CSV"
Call DataFileSave(CsvFilePath,"CSV")

Do note that the CSV export will only export one Group from the Data Portal.  If you need to export multiple groups, one to each file, then we can use the DataFileSaveSel() command.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 5 of 10
(7,341 Views)

Thanks Brad, I'll give this a try.

0 Kudos
Message 6 of 10
(7,335 Views)

I'm getting an error when trying this script (see attachment).

 

If anyone has any ideas what the cause of this is, I would appreciate any feedback.

 

Thanks,

0 Kudos
Message 7 of 10
(7,230 Views)

Option Explicit prevents this from working.

0 Kudos
Message 8 of 10
(7,228 Views)

From the image you attached of the error, it appears that CsvFilePath is never declared in your script (i.e. Dim CsvFilePath) and will therefore be undefined.

Steven Gloor
Staff Customer Engineer - CTA, CLD
0 Kudos
Message 9 of 10
(7,191 Views)

Yes, Steven you are right. Removing the "option explicit" statement also allows this script to work.

0 Kudos
Message 10 of 10
(7,188 Views)