06-27-2017 04:15 PM
I have multiple data groups. I would like to export just a subset data of a specific data channel of each group (channel has same name as group's name); the subset is determined by FirstInd and EndInd. The following code I normally use to export channels of multiple group into csv file.
FirstInd = 1000
EndInd = 5000 Set oChannelExport = Data.GetChannels("") For Each oGrp in oChannelGroups ChannelName = oGrp.Name Call oChannelExport.Add(oGrp.Channels(ChannelName)) Next Call DataFileSaveSel(DestPath & "\Filter_Data" & ".csv", "CSV", oChannelExport)
I do not know how to use FirstInd and EndInd to export just a part of individual channel, instead of the whole channel. Please help me.
Thank you.
Solved! Go to Solution.
06-28-2017 01:28 AM
There is no direct way.
You need to copy those values to new channels.
following line can be used to copy a partial channel to a new one
call destChannel.SetValuesBlock(srcChannel.GetValuesBlock(FirstInd, EndInd - FirstInd))
which would result in code like this using a group that is deleted after work is done..
Option Explicit ''' Create example data data.Root.clear dim i : for i = 1 to 10 dim grpO : set grpO = data.Root.ChannelGroups.Add("group_" & i) grpO.Activate DataFileLoadSel "example.tdm", "TDM", "[2]/[1-3]" grpO.channels(2).name = grpO.Name Next ''' Create example data dim tGroup : set tGroup = data.Root.ChannelGroups.Add("tempGrp") dim FirstInd, EndInd, oChannelExport, oGrp, ChannelName FirstInd = 1000 EndInd = 5000 Set oChannelExport = tGroup.Channels For Each oGrp in data.Root.ChannelGroups ChannelName = oGrp.Name if oGrp.Name <> tGroup.Name then dim tChannel : set tChannel = oChannelExport.Add(oGrp.Name,DataTypeFloat64) call tChannel.SetValuesBlock(oGrp.Channels(ChannelName).GetValuesBlock(FirstInd, EndInd - FirstInd)) end if Next Call DataFileSaveSel(TmpDrv & "Filter_Data" & ".csv", "CSV", oChannelExport) set tGroup = nothing set oChannelExport = nothing data.Root.ChannelGroups.Remove("tempGrp")
06-28-2017 09:01 AM
The solution is perfect for me.
Thank you very much.