DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get selected channel Index

Is it possible to read the index of the currently selected item within the data portal?

I have several sets of data that I want to perform calculations on eg:

 

Set 1

|_  Data A

|_ Data B

|_ Data C

|_ CalcResult

Set 2

|_  Data A

|_ Data B

|_ Data C

|_ CalcResult

 

etc

 

I want to be able to click on Set 1 and perform a calculation script, then select Set 2 and perform the same calculation.....

I don't want it to perform all of the calculations at once because I need to review the calculated channel before moving onto the next.

 

Thanks in advance

 

 

 

0 Kudos
Message 1 of 4
(3,007 Views)

Hi SSK,

 

Thank you for posting this question. I would like to check up on this post since no one in the community has gotten back to you yet. 

 

Here is some example code that will go through all your data groups, and every channel within these. I hope this will demonstrate the syntax for you.

 

Dim indexGroup, channelIndex, sChnName

For indexGroup = 1 to Data.Root.ChannelGroups.Count 'loops through all groups

 

For channelIndex = 1 to Data.Root.ChannelGroups(indexGroup).Channels.Count 'loops through every channel within the group


sChnName = Data.Root.ChannelGroups(indexGroup).Channels(channelIndex).properties("name").Value
If (sChnName = "Noise_1") then

Call ChnCalculate("ch(""["& indexGroup &"]/Results Channel"")=ch(""["& indexGroup &"]/Noise_1"")")

End If


Next

 

Next

 

If you would like to refer to both the groups and channels by index, you will have to change your settings. Instructions for this can be found here here:  

http://zone.ni.com/reference/en-XX/help/370858K-01/genshell/genshell/genshell_data_channels/

 

I hope this is helpful for you.

 

Best regards,

Sara Nordin Hällgren

Applications Engineer

National Instruments

 

0 Kudos
Message 2 of 4
(2,950 Views)

Hi ssk,

 

If you want to return the list of selected Groups in the Data Portal, here's the approach you can use:

Set SelectedGroups = GetSelectedGroups()
LogFileWrite ":"
LogFileWrite "List of Selected Groups"
LogFileWrite "-----------------------"
FOR Each Group In SelectedGroups
  LogFileWrite Group.Name
NEXT ' Group


Function GetSelectedGroups()
  Dim SelectedGroups, Element, Group
  Set SelectedGroups = Data.CreateElementList()
  FOR Each Element In Portal.Structure.Selection
    IF Element.IsKindOf(eDataRoot) THEN
      Call SelectedGroups.RemoveAll()
      FOR Each Group In Element.ChannelGroups
        Call SelectedGroups.Add(Group)
      NEXT ' Group
      Exit For ' Element
    ElseIF Element.IsKindOf(eDataChannelGroup) THEN
      IF NOT SelectedGroups.Exists(Element) THEN
        Call SelectedGroups.Add(Element)
      END IF
    ELSE ' Channel
      IF NOT SelectedGroups.Exists(Element.ChannelGroup) THEN
        Call SelectedGroups.Add(Element.ChannelGroup)
      END IF
    END IF
  NEXT ' Element
Set GetSelectedGroups = SelectedGroups
End Function ' GetSelectedGroups()

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 4
(2,901 Views)

And here's what it looks like to request all the selected Channels in the Data Portal:

Set SelectedChans = GetSelectedChans()
LogFileWrite ":"
LogFileWrite "List of Selected Channels"
LogFileWrite "-----------------------"
FOR Each Channel In SelectedChans
  LogFileWrite Channel.Name
NEXT ' Group


Function GetSelectedChans()
  Dim SelectedChans, Element, Group, Channel
  Set SelectedChans = Data.CreateElementList()
  FOR Each Element In Portal.Structure.Selection
    IF Element.IsKindOf(eDataRoot) THEN
      Call SelectedChans.RemoveAll()
      FOR Each Group In Element.ChannelGroups
        FOR Each Channel In Group.Channels
          Call SelectedChans.Add(Channel)
        NEXT ' Channel
      NEXT ' Group
      Exit For ' Element
    ElseIF Element.IsKindOf(eDataChannelGroup) THEN
      FOR Each Channel In Element.Channels
        Call SelectedChans.Add(Channel)
      NEXT ' Channel
    ELSE ' Channel
      Call SelectedChans.Add(Element)
    END IF
  NEXT ' Element
Set GetSelectedChans = SelectedChans
End Function ' GetSelectedChans()

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 4
(2,900 Views)