ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

CSV Export with Units

Solved!
Go to solution

 Brad, I don't see an option in Diadem 2018 for exporting properties as a row.  The only options i see are Separator, Decimal Separator, File Encoding, Time format, and Enclosing text with double quotes.

Is there a secret parameter available in scripting export channel properties as a row of a csv file?  Or is your workaround still the only way?

0 Kudos
Message 11 of 15
(1,686 Views)

Sorry DIAdem 2018 still does not include such a feature.

So the workaround is still the only way.

0 Kudos
Message 12 of 15
(1,679 Views)

Hey there experts,

I'm quite new to vbs scripting but now I have the task to rewrite our old script from 2012.

I added the following code to export my data as an csv file:

Option Explicit  'Erzwingt die explizite Deklaration aller Variablen in einem Script.
Dim oMyChannelList, dateiexcel, pfad, versuch

Set oMyChannelList = Data.GetChannels("[2]/[1]")
Call oMyChannelList.Add(Data.Root.ChannelGroups(2).Channels(2))
Call oMyChannelList.Add(Data.Root.ChannelGroups(2).Channels(3))

versuch = "Versuchsnummer"                                                       'kann im biax script entfallen, da der jeweilige Versuchsname in Zeile 95 an das Script übergeben wird.

Dim MyFolders()
Call FolderCreate("C:\Users\Andre\Desktop\Excel Export\" & versuch & "\")        'erstellt einen neuen Ordner mit dem Entsprechenden Versuchsnamen

ReDim MyFolders(1)
MyFolders(0)=("C:\Users\Andre\Desktop\Excel Export\" & versuch & "\")            'muss im Script entsprechend auf den Ordner Versuche angepasst werden
                                                                       
Call DataFileSaveSel(MyFolders(0)& versuch & ".csv","CSV", oMyChannelList)
Call DataFileSaveSel(MyFolders(0)& versuch & "eng.csv","CSV", oMyChannelList)

function CsvParameters(byval filePath, byVal lang)                               'konfiguriert die CSV Datei in Bezug auf Trennzeichen und Spaltentrennung etc.
  select case lang
    case "ger"
      CsvParameters = "<filename>" & replace(filePath, "&", "&amp;") _
      & "</filename><decimalpoint>,</decimalpoint><delimiter>;</delimiter><timeformat>DD.MM.YYYY hh:mm:ss</timeformat>"
    case "eng"
      CsvParameters = "<filename>" & replace(filePath, "&", "&amp;") _
      & "</filename><decimalpoint>.</decimalpoint><delimiter>,</delimiter><timeformat>MM/DD/YYYY hh:mm:ss pp</timeformat>"
    case else
      CsvParameters = filePath
  end select
  
end function

But as always the export is without units. Now I don't know where to fill in the Code that Brad provided many years ago, or is there a better method by now?

 

Thanks in advance and I would appreciate any help! 😉

0 Kudos
Message 13 of 15
(1,565 Views)

Hi Andre,

 

My script was so old it wouldn't run in DIAdem 2020, so I had to update it and simplify it some.  See if this gives you the idea how to hot-swap the next few header lines for the name of the last channel being exported.  The only down-side is that any "/" characters in the get turned into "\" because of the Group/Channel requirement to be unique.

OPTION EXPLICIT
Dim FileNamePath, HeaderLines, Group
Call DataDelAll
Call DataFileLoad(AutoActPath & "Example.tdm")
FileNamePath = AutoActPath & "Example.txt"
HeaderLines = "Version 1.10" & vbCRLF & RTT(TTR(CurrDateTime), "#yyyy-mm-dd hh:nn:ss.ffff")
'Set Group = Data.Root.ActiveChannelGroup
Set Group = Data.Root.ChannelGroups(1)
Call GroupAsciiExport(Group.Channels, FileNamePath, HeaderLines)
Call ExtProgram(FileNamePath)


Sub GroupAsciiExport(Channels, FileNamePath, HeaderLines)
  Dim j, Ch1, ChN, HdrStr, SelChans, ExportGroup, SourceGroup, SourceChan, SourceName
  j = Channels.Count
  HdrStr = GetHdrStr(Channels)
  Ch1 = Channels(1).Name
  ChN = Channels(j).Name
  Channels(1).Name = HeaderLines & vbCRLF & Ch1 
  Channels(j).Name = ChN & vbCRLF & HdrStr
  Call DataFileSaveSel(FileNamePath, "CSV", Group.Channels)
  Channels(1).Name = Ch1
  Channels(j).Name = ChN
End Sub ' GroupAsciiExport()


Function GetHdrStr(Channels)
  Dim j, Channel, HdrStr
  FOR Each Channel In Channels
    HdrStr = HdrStr & ChnDim(Channel)  & vbTAB
  NEXT ' Channel
  HdrStr = Left(HdrStr, Len(HdrStr)-1) & vbCRLF
  FOR Each Channel In Channels
    HdrStr = HdrStr & ChnComment(Channel) & vbTAB
  NEXT ' j
GetHdrStr = HdrStr
End Function ' GetHdrStr()


' "filename"             specifies the file that is to be read. 
' "characterset"         can have two possible values: utf16 (bmp) and ansi. Future possible values include UTF8, etc. 
' "delimiter"            is the character used to seperate values. Only tab, semi-colon, and comma will be supported in the first version 
' "numstartrow"          is the index of the row to start reading at. 
' "firstrowchannelnames" is true if the first row contains the names of the channels following it. 
' "firstcolumntime"      indicates that the first column contains time data. These times will be interpreted as absolute times. 
' "decimalpoint"         indicates whether a "." or a "," is used to seperate the integral part of the number from the fractional part. 
' "timeformat"           indicates what time format to expect in the document and how to write the time format back out again. 

 

Brad

Message 14 of 15
(1,552 Views)

Hi Brad,

 

thanks a lot for your effort! It seems all is working as planned. 😃

(sorry for the late reply =/ )

 

Best regards,

Andre

0 Kudos
Message 15 of 15
(1,502 Views)