12-14-2017 08:56 AM
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
01-09-2018 07:16 AM
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
01-31-2018 02:10 PM
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
01-31-2018 02:16 PM
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