From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Diadem script- need help modifying the script

Hello,

I am new to scripting, hoping I can get some help here.
I have 200+ tdms files that i need to add a calculated channel in each one of them.
The way I have been doing it is I load each file separately, I have a script that I run to add the calculated channel, then I manually save the new tdms file on the drive.
I would like to have a script that can load all the files at once, add the calculated channel that I need and save the files somewhere else on the drive.
The script that I have looks like this
" Option Explicit 
Call Calculate("ch(""[1]/Calculated_channel"")=(Ch(""[1]/Channel_1"")-Ch(""[1]/Channel_2""))*2",NULL,NULL,"")".
lets say I have 10 tdms files in "folder 1" on C drive, and I want to have my output files (that contains the calculated channel) saved in "folder 2" on C drive.
How do modify my script to do that
Appreciate any help

0 Kudos
Message 1 of 7
(2,526 Views)

Hi MikeKass89,

 

If you open up DIAdem and go to Help >> Find Examples, there's an example that does pretty close to what you're asking. In the "Mining and Loading Data" folder, there's an example called "Parallel File Analysis". This gives you the option to perform an analysis on all the results of a DIAdem query.

It also gives instructions for how to add a user-defined analysis function, which you could take advantage of to add your script's functionality.

NickelsAndDimes
Product Support Engineer - sbRIO
National Instruments
0 Kudos
Message 2 of 7
(2,495 Views)

I couldn't find "Parallel File Analysis", I have the 2012 version maybe that's why!

 

I am running out of time, It should be a small modification, can you please modify it and show me what it is supposed to look like, would really appreciate it

0 Kudos
Message 3 of 7
(2,481 Views)

Hi Mike,

 

The script below will process as many files that are in the path, and will then save the data to the junkout path.

You Just change the paths for your needs, and add the processing of adding the channel of interest you have.

 

Paul

 

 

'-------------------------------------------------------------------------------
'-- VBS script file
'-- Created on 12/17/2018 20:18:22
'-- Author:
'-- Comment:
'-------------------------------------------------------------------------------
Option Explicit 'Forces the explicit declaration of all the variables in a script.

dim sStartPath : sStartPath = "c:\junk\"
dim sEndPath: sEndPath = "c:\junkout\"

Dim ofso,oFolder,oFile,oFiles
Set ofso = CreateObject("Scripting.FileSystemObject")

set ofolder = oFso.GetFolder(sStartPath)

set oFiles = oFolder.Files
dim sExt,sFileName
for each oFile in oFiles
sExt = namesplit(oFile.Name,"E")
sFileName = namesplit(oFile.Name,"N") & "." & sExt
if ucase(sExt) = "TDMS" then
data.Root.Clear ' clears dataportal
' Do processing on file here

call datafileload(oFile.Path,"TDMS","load")
' then save to new filepath
call datafilesave(sEndPath&sFileName)

end if
next

0 Kudos
Message 4 of 7
(2,475 Views)

Hi Paul,

I did that and ran the script but I get an error that the channel I am trying to add to the files is unknown.

the error I get is "input channel "CH[1]/scaled" is unknown.

I never had that issue when I loaded one file at a time, do you know what I need to add to define the new channel, I appreciate your help.

this is what my script looks like now

Option Explicit 'Forces the explicit declaration of all the variables in a script. 

dim sStartPath : sStartPath = "C:\DIAdem\Temp data files\"

dim sEndPath: sEndPath = "C:\DIAdem\Output files\" 

Dim ofso,oFolder,oFile,oFiles

Set ofso = CreateObject("Scripting.FileSystemObject") 

set ofolder = oFso.GetFolder(sStartPath) 

set oFiles = oFolder.Files

dim sExt,sFileName

for each oFile in oFiles

sExt = namesplit(oFile.Name,"E")

sFileName = namesplit(oFile.Name,"N") & "." & sExt

if ucase(sExt) = "TDMS" then

data.Root.Clear

 

call Calculate("ch(""[1]/scaled"")=(Ch(""[1]/channel1"")-Ch(""[1]/channel2""))",NULL,NULL,"") ' I got the error at this line

 

call datafileload(oFile.Path,"TDMS","load")

call datafilesave(sEndPath&sFileName)

end if

 

Regards,

Mike

0 Kudos
Message 5 of 7
(2,469 Views)

Try loading the channel before you calculate!

0 Kudos
Message 6 of 7
(2,466 Views)

it didn't work either. Even if it worked, my goal is to be able to do multiple files at once!

I think I need to define the variable for calculated channel that I am adding but I am not sure how, any idea?

 

Regards,

Mike

0 Kudos
Message 7 of 7
(2,455 Views)