LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
cbutcher

Unbundle by Enum

Status: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.

This previously wasn't such a useful idea, because typically the datatypes unbundled would be different, requiring a To Variant to be able to get anywhere. This is still the only way I can see to do this (and unless I look into scripting, it's fairly time consuming):

 

Unbundle with one case per valueUnbundle with one case per value

Would it be possible to get either

a) a primitive node that takes an Enum and a Cluster as inputs, and outputs the data element matching the value of the enum as a variant (as in the code above). This can break at edit time if the enum contains any values which are not the labels of an element of the cluster, in a way similar to the case structure if the case is not covered by an enum value (but in reverse, I suppose. So then more like not having all values or default...).

 

b) far more excitingly (but I don't see how it would be possible) a VIM that outputs the data value without the variant. I can't quite see this being possible, since the value of an enum requires runtime information whilst the datatype output needs to be available at edit time, but I'll list it as a tentative dream.


GCentral
4 Comments
cbutcher
Trusted Enthusiast

The Get Cluster Information VI in Data Type Parsing (under Variant) outputs an array of Variants, which can be indexed by a numeric value (somewhat like an enum) providing the same functionality if the enum and the cluster have the same order.

 

Combined with Get Type Information for the label and string matching after a Format To String on the Enum, you could match enums and clusters with different orders, but that presumably would be slower than a better solution.

GetTypeVersion.PNG

 

This provides types, but only provides default values. Consequently, useless for this application, as far as I can see.

 

 

 


GCentral
wiebe@CARYA
Knight of NI

You can get the values, simply use Variant to Data to convert the cluster to an array of variants.

Cluster to Array of Variants.png

FYI, Each array element will still have the original label as well.

 

When this is done in a VIM, things will be dramatically slow compared with a simple unbundle.

 

Also, to me it's ambiguous. The Enum is an integer, so I'd think the element would be "unbundled" by index (enum=0, unbundle element 0).

nanocyte
Active Participant

A native solution would be nice but until then I wrote a script to take a cluster type def and generate:

  1. An enum with one entry per element in the cluster
  2. A case structure with one frame per enum element
  3. An unbundle in each frame corresponding to the cluster

create selector for cluster type def.png

The bundle by enum case would be very similar code except you'd have to

  1. Change the variant to a control instead of an indicator
  2. Add variant to data instead of to variant.
  3. Add a bundle by name. Extra points if you use the in place nodes.

It would not be too difficult to make a menu plugin from this

 

One last suggestion—the inability to get a cluster's element dynamically has been noted and one solution would be to use variant attributes

Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.