I am trying to run a filter on data by using a loop that goes through all the groups, finds the relevant channel and perform the filter.
the debuger send the following massage:
invalid channel in command ChnFiltCalc.
I will apprechiate your assistance solving this issue
the code is:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim i, j, oMyChn, oMyUnit, oMyName, oMyGroup
For i = 1 to GroupCount
For j = 1 to GroupChnCount(i)
' Set oMyChn = Data.Root.ChannelGroups(i).Channels(S1PELV0000H2ACZA)
Set oMyChn = Data.Root.ChannelGroups(i).Channels(j)
Set oMyUnit = oMyChn.Properties("unit_string")
set oMyName = oMyChn.Properties("name")
set oMyGroup= oMyChn.Properties("groupname")
If oMyUnit.Value = "gn" Then
if oMyName.value = "S1PELV0000H2ACZA" then
Call ChnFiltCalc("","[oMyGroup.Value]/oMyName.Value","/PELVIS_AC_FILTERED","IIR","Butterworth","Low pass",4,100,0,0,1.2,25,"Hamming",1,1)
Data.Root.ChannelGroups(i).Channels("FilteredSignal").Name = "PELVIS_AC_FILTERED"
If oMyUnit.Value = "m/s^2" Then
The reason for your problem is that oMyGroup.Value and oMyName.Value are interpreted as string. The correct syntax for this would be:
"""[" & oMyGroup.Value & "]/" & oMyName.Value & """". That's a bit complex, but the correct VBS syntax
Alternatively your script code can look like this (in addition I use the quantity based calculation):
CalcQuantityBased = true Dim i, j, oCurrChn, oResChn, oGroups, oCurrGroupChns set oGroups = Data.Root.ChannelGroups for i = 1 to oGroups.Count set oCurrGroupChns = oGroups(i).Channels for j = 1 to oCurrGroupChns.Count set oCurrChn = oCurrGroupChns(j) if oCurrChn.Name = "S1PELV0000H2ACZA" then set oResChn = oCurrGroupChns.Add("PELVIS_AC_FILTERED", DataTypeChnFloat64) Call ChnFiltCalc("", oCurrChn, oResChn, "IIR", "Butterworth", "Low pass", 4, 100, 0, 0, 1.2, 25, "Hamming", 1, 1) end if next next
I raising this subject again althought it is concerning a different function but the problem is the loop.
I am trying to substract two channels and create a results channel. The problem is how to do it automatily for all the groups in the file. The substracted channel have the same name in all the groups.
When I record the macro for one group I received the following script:
Call ChnSub("/SEAT PAN VEL","/BASE PLATE VEL","/Subtracted")
Data.Root.ChannelGroups(1).Channels("Subtracted").Name = "BUCKET RELATIVE VEL"
I am trying to replae the  with a variable that can be used through a loop. I tried this without success:
Dim i, oMyGrp
For i = 1 to GroupCount
sMyResult = Str(oMyGrp)
Call ChnSub("sMyResult/SEAT PAN VEL","sMyResult/BASE PLATE VEL","/Subtracted")
Data.Root.ChannelGroups(i).Channels("Subtracted").Name = "BUKET RELATIVE VEL"
I will apprichiate your help on this subject.
Please try this:
dim i, oGroups, oChnA, oChnB, oChnRes set oGroups = Data.Root.ChannelGroups For i = 1 to oGroups.Count set oChnA = oGroups(i).Channels("SEAT PAN VEL") set oChnB = oGroups(i).Channels("BASE PLATE VEL") set oChnRes = oGroups(i).Channels.Add("BUKET RELATIVE VEL",DataTypeChnFloat64) Call ChnSub(oChnA, oChnB, oChnRes) Next
I tried the code and received the following error:
"The index SEAT PAN VEL does not much any any of the elements in the list"
When I change the name to another channel that as an ISO code name the is working.
the SEAT PAN VEL channel as well as the BASE PLATE VEL were created through Diadem analysis and I only changed there names.
Is there a different reference name for this chanels that I m not aware of?
Thanks for your support
Dissregard above post it was my mistake. The code works just fine. The problem was in my file.
I really appriciate your effort