DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I sort channels by a custom property?

Hello.
 
I have written a script that creates a series of formatted charts in View.  The data comes from TDMS files with several groups of channels with some custom properties assigned to the channels.  I would like to sort the channels within each group by one of these custom properties so that the curves display in the desired order.
 
It appears that ChnMove and ChnRenumber can be used to reorder the channels, but how can I programatically sort the channels by a channel property?
 
Thanks,
Craig
0 Kudos
Message 1 of 5
(4,497 Views)

Hi Craig,

If I understand you correctly, you wish to sort the order in which the curves appear in the VIEW legend, is that correct?  One way to do this would be to programmatically assign the X and Y channels for each curve with the VIEW object variable in a VBScript.  In this case it does not matter how the channels are arranged or named, since you will just assign the Group/Channel path for each channel to the correct VIEW curve.

Another way to do this would be to re-order or re-name the groups/channels in the Data Portal, but what you do in this case depends on how you are referencing the channels in the VIEW graphs.  The standard channel referencing in DIAdem is [GroupIndex]/ChannelName, is this how you are referencing the channels for each VIEW curve?  How are your data channels arranged in the DataPortal-- the data channels for each curve in a separate group, or all the channels in the same group?  Do the channels have different names?

If all the channels for a given VIEW graph are in the same group and named differently, and if you want to achieve your goal without using the VIEW object variable, then you need to change your VIEW layout so that it references the channels by channel index, i.e.

[GroupIndex]/[ChannelIndex]  ---> [1]/[1]
GroupName/[ChannelIndex]  --->  Example/[1]

Now if you reorder the channels within that Group based on their custom property value with the ChnMove() command, their display order in the VIEW graph will change.

Ask if you have further questions,
Brad Turpin
DIAdem Product Support Engineer
National Instrument

0 Kudos
Message 2 of 5
(4,485 Views)

Brad,

Yes, I would like to sort the order of the curves in the legend and since I am using the "n Systems" display type, I assume this order of the curves on the graph will match this.

The channels that I want to display on a given graph are in the same group and they have different names.  Because the names of the channels are variable and unknown when the file is loaded, I use the [GroupIndex]/[ChannelIndex] syntax to refer to them.  I think I understand how to reorder them with the ChnMove() command, but I'm not sure how to actually sort by a property.  Do I need to populate an array with the property values, sort this with some string functions, and then reassign all the channels based on this, or is there a function in DIAdem that would simplify this process?

Thanks,

Craig

0 Kudos
Message 3 of 5
(4,482 Views)

Hello Craig!

Unfortunately DIAdem doesn't have a adequate command. You have to use some lines of script code. Try this bubblesort adaption:

Option Explicit
 
Call GroupChnSort(1,"name")
 
Sub GroupChnSort(ByRef nGroupIndex, ByRef sgPropName)
  Dim i
  Dim j
  Dim n
  Dim anCNo()
 
  If GroupChnCount(nGroupIndex) > 1 Then
    ReDim anCNo( GroupChnCount(nGroupIndex)-1 )
 
    For i=1 To GroupChnCount(nGroupIndex)
      anCNo(i-1) = i
    Next
 
    For i = 0 to UBound(anCNo)
      For j = i+1 to UBound(anCNo)
        If ChnPropValGet("[" & nGroupIndex & "]/[" & anCNo(i) & "]", sgPropName) > _
           ChnPropValGet("[" & nGroupIndex & "]/[" & anCNo(j) & "]", sgPropName) Then
          n        = anCNo(i)
          anCNo(i) = anCNo(j)
          anCNo(j) = n
        End If
      Next
    Next
 
    For i=1 To GroupChnCount(nGroupIndex)
      Call ChnMove( anCNo(i-1), nGroupIndex, i)
    Next
  End If
End Sub

The string compare is casessensitive. You can wrap the ChnPropValGet with a UCase to change this.

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 4 of 5
(4,468 Views)
Thank you.  I was able to adapt the bubblesort code for my application and it does what I needed.
-Craig
0 Kudos
Message 5 of 5
(4,387 Views)