Example Code

Load Search Results as Single Channel in DIAdem

Overview

Sometimes data spans multiple files but you want to work with it as a single channel. This allows (assuming a suitable search has been performed) this to happen.

Description

This works by loading the list of the results of the navigator, driving the main requirement: the data channels must be the results in the navigator window in the order in which you want them concatenated.


The script loads this list and loads the channels one by one, but for each channel it appends it to the first and then deletes it again. It is also attached below.

dim oResultChannels, oCurrChannel, oLoadedChannel, sFirstChannel

set oResultChannels = Navigator.Display.CurrDataFinder.ResultsList

For Each oCurrChannel in oResultChannels.Elements 'Could change to only selected.

  'Either make first channel or load into existing channel.

  If isEmpty(sFirstChannel) Then

    'Loads root and channel group first time.

    Set oLoadedChannel = Navigator.LoadData(oCurrChannel,"Load").Item(1)

   

    'Handle first may load as root or group if it did not exist.

    If oLoadedChannel.IsKindOf(eDataRoot) Then

      Set oLoadedChannel = oLoadedChannel.ChannelGroups.Item(1).Channels.Item(1)

    ElseIf oLoadedChannel.IsKindOf(eDataChannelGroup) Then

      Set oLoadedChannel = oLoadedChannel.Channels.Item(1)

    End If

    'Assign the reference.

    sFirstChannel = oLoadedChannel.GetReference(eRefTypeNameName)

   

  Else ' Append the channels.

  'This should now only load as a channel so removed the checking here.

  set oLoadedChannel =  Navigator.LoadData(oCurrChannel,"Load").Item(1)

    Call ChnConcat(oLoadedChannel.GetReference(eRefTypeNameName),sFirstChannel)

    Call ChnDelete(oLoadedChannel.GetReference(eRefTypeNameName))

  End If

Next

Steps to Implement or Execute Code

  1. Perform a query with the navigator. It must result in a series of channels in the display.
  2. Run the attached script and see the data loaded into a single channel.

Requirements to Run

Software

  • DIAdem 2012 (Should work versions at least back to 2010)
James Mc
========
Ask me about Rust & NI Hardware
My writings are at https://www.wiresmithtech.com/devs/

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors