DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Change name of channelgroup to its actual filename

Solved!
Go to solution

Hello,

 

I want to change the name of a channelgroup to the actual filename of the tdms/data file.

 

Once data is loaded into Diadem, the root will be named as the filename of the tdms file and the channelgroups will be named the same name as the tabs in the tdms file.

 

Since I want to load several tdms files into one root and I want to change the name of the channelgroups to distinguish them apart.

Not just adding additonal text I want to change it to the filename of the tdms file itself.

 

So far I know this

 

'Change Channelgroup 1 name to Test 1.  
Data.Root.ChannelGroups(1).Name = "Test 1"
'Change Channelgroup 1 name to its root name.
Data.Root.ChannelGroups(1).Name = Data.Root.Name

 

I cant find any filename or filepath.

 

 

 

/Nilfheim

 

 

0 Kudos
Message 1 of 12
(323 Views)
Highlighted

Hi Nilfheim,

 

This can be done different ways, so I will give you the way I would do it. (Others can post theirs if they like!)

 

1) To get the file name to show up in a property (even when are loading multiple files

   Need to make a setting in   Settings |  Navigator |  and then look at the loading  Behavior Tab.  

   Configure Property inheritance level to "Move to Loaded  level"  This will make is so that when  a file is loaded into portal it will copy all Root properties to the Group level with the "root" descriptors.  Then when you load multiple files you can always take  a look at the property and file out what file it came from.

2)  To read this file name or Change the group name.

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.
dim oGrp: set oGrp = data.Root.ChannelGroups("Name of Group")
dim sFilename
sFilename = oGrp.Properties("root~name").Value

oGrp.Name = sFilename

 

Note: The group or channel names should not have "/" or "\" characters in them.  These mess with the group/channel separator that DIAdem users.  Should also make sure that clean up the group name some.   Screwy characters can cause problems.

 

3)  To iterate over all group

dim oGrp

dim oGrps : set oGrps = data.GetChannelGroups("*")
for each oGrp in oGrps

logfilewrite oGrp.Name
next

 

Paul

 Viviota.com

 

 

 

 

 

 

 

Message 2 of 12
(277 Views)

Thank you Pesmith8,

 

This question wasn't in the initial statement,

If I would just want to rename specific channelgroups like 1,3,5,7 and let the others keep their name.

It should be a combination of a for loop but since we are using 'for each' with object its making me confused.

How should i combine it?

 

 

Just a note on step 3 for others.

I just added it so it would actually change the name instead of just writing the names in the log.

 

dim oGrp
dim oGrps : set oGrps = data.GetChannelGroups("*")
for each oGrp in oGrps
dim sFilename
sFilename = oGrp.Properties("root~name").Value
oGrp.Name = sFilename
next

 

/Niflheim

 

0 Kudos
Message 3 of 12
(255 Views)

/Niflheim,

 

Try this out

 

You can add as many if statements as need to the group rename

 

dim iGroups: iGroups = data.Root.ChannelGroups.Count
dim i,x,y,z
for i = 1 to iGroups
if data.Root.ChannelGroups.Item(i).Name = "1" then
data.Root.ChannelGroups.Item(i).Name = "NewName"

end if

next

logfilewrite iGroups

 

Paul

0 Kudos
Message 4 of 12
(248 Views)

Hi Nilfheim,

If you are looking for file name or file path, please have a look at the channel properties:

grafik.png

If you drag & drop a property into the script editor you get the syntax.

Greetings

Walter

 

0 Kudos
Message 5 of 12
(242 Views)

@Pesmith8

Thank you, however I think I stated my question wrong so let me rephrase my question.

 

I want to rename every other channelgroup,  like number 1,3,5....

The names of the channelgroups will be random and not specific stated 1,3, 5..., could be random dates etc

It shall also be named to the filename as before.

 

I have tried myself but I cannot get it to work.

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.
'-------------Count the groups
dim iGroups: iGroups = data.Root.ChannelGroups.Count 
dim i
'-------------Step through every other group
For i = 1 To iGroups Step 2
dim oGrp
dim oGrps : set oGrps = data.GetChannelGroups(i) 
for each oGrp in oGrps
  
  
'-------------Rename to root name
    dim sFilename
    sFilename = oGrp.Properties("root~name").Value
    oGrp.Name = sFilename
    
    
next
next

 

 

 

How do I go through all the groups or each other and rename them to root?

To implement "every other" channelgroup, is it better to use a for loop with step 2 or comparing like with modulus, ie mod?

 

In my code Im very unsure about this

 

dim oGrps : set oGrps = data.GetChannelGroups(i)

In your previous example you used astrix which I presume means all channels.

 

 

@Walter_Rick
Thank you, it's good to know.

The change of settings that Pesmith8 noted was essential for this to be solved.

 

 

Thank you, you save me a lot of time.

Niflheim

0 Kudos
Message 6 of 12
(234 Views)
Solution
Accepted by topic author Niflheim
05-23-2019 03:43 AM

Hello Nilfheim,

 

A for loop with STEP is faster than modulo.

In general this loop should work:

dim iLoop, iMaxGroup, oGroups, oCurrGroup

'----- option one
set oGroups = Data.Root.ChannelGroups
iMaxGroup = oGroups.Count

for iLoop = 1 to iMaxGroup step 2
  set oCurrGroup = oGroups(iLoop)
  msgbox oCurrGroup.Name
  oCurrGroup.Name = "New name"
next

If you want skipping the first group, then start the for loop with 2.

If you want running over all groups delete the STEP parameter.

Keep in mind that group names and channel names (within the group) must be unique. Otherwise it will be automatically up-counted.

 

Greetings

Walter

Message 7 of 12
(227 Views)

Thank you Walter that worked.

 

For future references: The final version I used. 

dim iLoop, iMaxGroup, oGroups, oCurrGroup

'-------------Set all groups
set oGroups = Data.Root.ChannelGroups
'-------------Count the groups
iMaxGroup = oGroups.Count
'-------------Step through every other group
for iLoop = 1 to iMaxGroup step 2
  set oCurrGroup = oGroups(iLoop)
'-------------Rename current group to root name oCurrGroup.Name = oCurrGroup.Properties("root~name").Value next

Thank you both Paul and Walter.

 

/Niflheim

0 Kudos
Message 8 of 12
(221 Views)

Just a small thing.

Performance is most of the time important. Also important is to know that in scripts each “.” and each indexing (especial string indexing like “root~name”) cost a bit time. In loops this can result in significant time consuming. (This is more a general information, if you have just a small number of iterations, you won’t see any difference.)

So, you can modify your script like this:

dim iLoop, iMaxGroup, oGroups, oCurrGroup, sRootName

sRootName = Data.Root.Name
'-------------Set all groups
set oGroups = Data.Root.ChannelGroups
'-------------Count the groups
iMaxGroup = oGroups.Count
'-------------Step through every other group
for iLoop = 1 to iMaxGroup step 2
  set oCurrGroup = oGroups(iLoop)
'-------------Rename current group to root name
  oCurrGroup.Name = sRootName
next

Also time consuming is the set command. If you only modify the group name you can delete this command line and use this assignment

oGroups(iLoop).Name = sRootName

If you have more actions with the group, the set command makes sense.

 

Greetings

Walter

0 Kudos
Message 9 of 12
(213 Views)

Good to know.

 

However, your example just sets the channelgroups to the main root, I want it to be set to each root of their own.

In order to do that I had to change the loading behaviour according to what Paul noted.

 

Then I guess these custom properties for each channelgroup are created when loaded:

 

Data.Root.ChannelGroups(7).Properties("root~author").Value
Data.Root.ChannelGroups(7).Properties("root~datetime").Value
Data.Root.ChannelGroups(7).Properties("root~description").Value
Data.Root.ChannelGroups(7).Properties("root~name").Value
Data.Root.ChannelGroups(7).Properties("root~title").Value

 

I still don't grasp exacly how you obtain the root name of that specific group.

 

Best

/Niflheim

 

0 Kudos
Message 10 of 12
(202 Views)