ni.com is currently experiencing issues.

Support teams are actively working on the resolution.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ChnFiltCalc with a loop

Hello

 

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

 

thanks

Oded

 

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
Call ChnUnitConvert(oMyChn,oMyChn,"m/s^2")
End If
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"
end if
If oMyUnit.Value = "m/s^2" Then
Call ChnUnitConvert(oMyChn,oMyChn,"gn")
End If
Next
Next

0 Kudos
Message 1 of 7
(4,655 Views)

Hello odedmi,

 

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

Greetings

Walter

0 Kudos
Message 2 of 7
(4,648 Views)

Thanks, Walter

 

Oded

0 Kudos
Message 3 of 7
(4,633 Views)

Hello

 

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 Data.Root.ChannelGroups(1).Activate()
Call ChnSub("[1]/SEAT PAN VEL","[1]/BASE PLATE VEL","/Subtracted")
Data.Root.ChannelGroups(1).Channels("Subtracted").Name = "BUCKET RELATIVE VEL"

 

I am trying to replae the [1] with a variable that can be used through a loop. I tried this without success:

Dim i, oMyGrp
Dim sMyResult
For i = 1 to GroupCount
 Call Data.Root.ChannelGroups(i).Activate()
 sMyResult = Str(oMyGrp)
 Call ChnSub("sMyResult/SEAT PAN VEL","sMyResult/BASE PLATE VEL","/Subtracted")
 Data.Root.ChannelGroups(i).Channels("Subtracted").Name = "BUKET RELATIVE VEL"
Next

 

I will apprichiate your help on this subject.

 

Thanks

Oded

0 Kudos
Message 4 of 7
(3,793 Views)

Hello odedmi,

 

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

Greetings

Walter

0 Kudos
Message 5 of 7
(3,778 Views)

Hello Walter

 

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

Oded

0 Kudos
Message 6 of 7
(3,749 Views)

Hello Walter

 

Dissregard above post it was my mistake. The code works just fine. The problem was in my file.

 

I really appriciate your effort

Oded

0 Kudos
Message 7 of 7
(3,743 Views)