From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.


Showing results for 
Search instead for 
Did you mean: 

Merge two element list from two diffrent groups



I'm trying to merge two element lists coming from two different groups. Some how the merge is not properly done. Is there a way to do it?

I can create a list of element coming from same group, but not coming from two different group.


Thank you for your help

0 Kudos
Message 1 of 7

Hello ThierryAlstom,


Are you referring to data channel lists that you want to merge in order to continue working with them?


You can obtain a channel list of specific channels using the Data.GetChannels(Reference) function. Use the Reference parameter to specify whether you want channels from a specific group or channels from several groups. In the case of multiple groups, no group name is specified, only the channel name or parts of the channel name, e.g. *Noise* for all channels that contain Noise in the name.


If you want to merge two channel element lists, then use the function AddElementList of the element list object. Take a look at the help page to learn more about the second parameter, which specifies how the lists are merged.


I've prepared an example for you:

' Load data only to show the example.
Call Data.Root.Clear()
Call DataFileLoad("EXAMPLE.TDM", "", "Load|ChnXYRelation")

' first possibility: get all channels over part of its name
dim Channels
set Channels = Data.GetChannels("*Noise*")
print("channel count: " & Channels.Count)

' second possibility: use AddElementList
dim ChnListMerge, ChnListNoise
set ChnListMerge = Data.GetChannels("Example/[1]")  ' First channel of group Example
set ChnListNoise = Data.GetChannels("Noise data/*") ' All channels of group Noise data
call ChnListMerge.AddElementList(ChnListNoise, ListMergeModeAdd)

' only to show the content of the merged list
dim Chn
for each Chn in ChnListMerge


0 Kudos
Message 2 of 7

Thanks for your reply.


So the merge works. But the issue is when I tried to save the channelist in CSV file. If I keep your code as example, it will save only the data from group "example", using this command line:


Call DataFileSaveSel(path+"TestResult.csv", "CSV", ChnListMerge)

0 Kudos
Message 3 of 7

Unfortunately, the DataFileSaveSel function cannot save multiple groups if you use CSV. This is pointed out in the help.




If you do not want to save the channel list as a TDM file, but still as a CSV file, there is the following workaround, which is not very elegant, but works. Copy all channels of the element list into a temporary group and specify this when saving. Then delete the group.


I have adapted the example as follows:

' Load data only to show the example.
Call Data.Root.Clear()
Call DataFileLoad("EXAMPLE.TDM", "", "Load|ChnXYRelation")

dim ChnListMerge, ChnListNoise
set ChnListMerge = Data.GetChannels("Example/[1]")
set ChnListNoise = Data.GetChannels("Noise data/*")
call ChnListMerge.AddElementList(ChnListNoise, ListMergeModeAdd)

' Create a temporary group and copy the channels into it to save them afterwards.
dim Chn, TempGroup
set TempGroup = Data.Root.ChannelGroups.Add("TempGroupForSaving")
for each Chn in ChnListMerge
  call TempGroup.Channels.AddChannel(Chn)

call DataFileSaveSel(CurrentScriptPath & "TestResult.csv", "CSV", TempGroup)

' Delete temporary group
call Data.Root.ChannelGroups.Remove(TempGroup.Name)
0 Kudos
Message 4 of 7

Yes I saw that but I was hoping that I missed something...


0 Kudos
Message 5 of 7

Unfortunately, the CSV export can only export one group. Copying the desired channels into one group is therefore the only workaround. Does the described solution work for you?

0 Kudos
Message 6 of 7

I understood. That works for me. thank you

0 Kudos
Message 7 of 7