From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to get the names of a cluster's elements in order?

Solved!
Go to solution

I've found the example for "Get Array Names from Cluster", which converts the cluster to an array of controls, but that doesn't give the names in order. (I'm trying to automatically get column names for a table). I can't find any property that says what the element's position is in the cluster.

0 Kudos
Message 1 of 8
(2,123 Views)
Solution
Accepted by topic author pblase42

In your cluster property node, don't use AllObjs[] property.  Use the Controls[] property.  It will give you all control references in order.

 

Message 2 of 8
(2,098 Views)

@RavensFan wrote:

In your cluster property node, don't use AllObjs[] property.  Use the Controls[] property.  It will give you all control references in order.

 


Just out of curiosity,

  1. Why do you "typecast" (to a more specific reference) to a control? (It appears the reference is already a generic control reference.)
  2. Why not expand the first property node to contain both Class Name and Text Label? (I know that won't speed up anything, just make the diagram cleaner.)
  3. If you are closing references, why not index the controls output and close all of them instead of only the last one?

mcduff 

Message 3 of 8
(2,085 Views)

Thank you very much!

0 Kudos
Message 4 of 8
(2,079 Views)

Basically because I've never worked with these properties before and I just cut-and-pasted from the example. Now that I know what I'm doing, I can pare it down.

0 Kudos
Message 5 of 8
(2,076 Views)

@mcduff wrote:

@RavensFan wrote:

In your cluster property node, don't use AllObjs[] property.  Use the Controls[] property.  It will give you all control references in order.

 


Just out of curiosity,

  1. Why do you "typecast" (to a more specific reference) to a control? (It appears the reference is already a generic control reference.)
  2. Why not expand the first property node to contain both Class Name and Text Label? (I know that won't speed up anything, just make the diagram cleaner.)
  3. If you are closing references, why not index the controls output and close all of them instead of only the last one?

mcduff 


All of those things you mentioned are remnants of the original code that the poster had sent.  I just fixed the part that was broken about cluster order.  I think the typecast made sense in his original code because the class was a GObj rather than a control.  I'm not sure what the use of ClassName is for in his code.

 

As for the Close reference, you are definitely right that  should be inside the For Loop.  Though I think this is one of those cases where you don't need to worry about closing that reference at all.

Message 6 of 8
(1,999 Views)

Or you make it easy on yourself and use 2 Variant VIs. 🙂

Get Cluster Element Names.png

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 8
(1,998 Views)

@pblase42 wrote:

...but that doesn't give the names in order.


To be clear, "in order" is ambiguous. Looking at your cluster, you're probably expecting the elements to be sorted based on their Y position, but there is nothing in LV which does that. If you want to achieve that, you would have to get the reference, extract the Y property and sort the referenced based on that.

 

The Controls[] property is sorted by tabbing order (which in the case of a cluster set to auto-arrange vertically is the same as sorting by the Y position) and the AllObjs[] property is sorted by Z order (because the cluster can include elements which can't be tabbed to and are therefore not in the tabbing list). Note that both of those orders can be changed (the tabbing by changing the tabbing order and the Z order by moving objects forward or backward), which will change the result you're getting.


___________________
Try to take over the world!
Message 8 of 8
(1,908 Views)