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
(550 Views)
Solution
Accepted by 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
(525 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
(512 Views)

Thank you very much!

0 Kudos
Message 4 of 8
(506 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
(503 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
(426 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! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 7 of 8
(425 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
(335 Views)