From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

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

Convert an Array of Variants into a Cluster

Status: New

It is common, in writing reusable code, to handle arbitrary clusters in variants.  To access the elements of the cluster, one wants to convert the cluster into an array of variants containing the individual items.  After access, one needs to convert the array of variants back into the original cluster.

 

There are several examples of packages that use this on NI.com and in the LAVAg.org Code Repository.  They mostly use functions for working with Variant Clusters from OpenG; however, these can be quite slow.   Recent LabVIEW versions have had the ability to do much of the functions quicker, however, there is a very imortant missing native ability: to convert an Array of Variants into a Variant Cluster.

 

The other direction, Cluster to Array of Variants, works like this:

Array of Variants to Cluster.png

But trying to reverse the process breaks:

Array of Variants to Cluster.png

 

So my idea is make the second image work; make an Array of Variants interchangable with a Variant Cluster in the "Variant to Data" LabVIEW primative. The interchangability should apply to contained subclusters/arrays also.  The matching of array to cluster elements can be by cluster order rather than element name.

 

This would greatly aid the performance of reuasable packages that operate on arbitrary clusters.

22 Comments
crossrulz
Knight of NI

If you can go one way, it only makes sense we should be able to go the other.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
AristosQueue (NI)
NI Employee (retired)

There's no technical reason this couldn't be done. The developer said he was thinking in terms of interrogating data and didn't think about going the other direction.

There is a minor tweak to your code that makes it work:

 

Untitled.png

drjdpowell
Trusted Enthusiast

Hi AQ.  Unfortunately, the need to statically specify the cluster size makes that tweak useless in generic-cluster code.

 

Though actually... maybe a better idea is an "Array-to-cluster" node that outputs a Variant Cluster, and thus dynamically adapts to the input array size.  Then your tweak would work generically.

AristosQueue (NI)
NI Employee (retired)

>  Unfortunately, the need to statically specify the cluster size

> makes that tweak useless in generic-cluster code.

 

How are you writing generic cluster code if you're specifying the cluster constant just one node later?

drjdpowell
Trusted Enthusiast

How are you writing generic cluster code if you're specifying the cluster constant just one node later?

 

Well, a real-world example using the OpenG Variant Config VIs is:

 

Generic Cluster example.png

Note the subCluster; that has to be treated internal to the generic OpenG VI.  

 

 

AristosQueue (NI)
NI Employee (retired)

In that example, you still have the cluster constant wired into the node, which means you would know exactly how many elements to specify in the Array To Cluster node. So while I agree that improving the node would be nice, the workaround I posted should still work for you in the meantime.

drjdpowell
Trusted Enthusiast

Well, OpenG works in the meantime Smiley Wink

Mathis_B
Member

Hi, from what I gather the function asked for does already exist. The only error came from wiring in the cluster directly into the variant to data function rather than an array of the cluster:

 

variant array to cluster array.png

 

edit: I'm sorry, I completely misunderstood the intentions of the example. And didn't understand that the author meant to map the variants onto individual cluster elements.

jcarmody
Trusted Enthusiast

This idea is looking for a single cluster out (with each element being one of the variant array elements), not an array of clusters.   Mathis caught it while I was posting.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

drjdpowell
Trusted Enthusiast

Interestingly, I've found that "Database Variant to Data" does support converting arrays of variants to clusters:

Database Variant to Data.png

The Database Toolkit this primative is from is an example of something that needs to work on arbitrary clusters, and obviously someone from NI encounterd and solved this problem previously, but only with a specialist version of Variant to Data.   And unfortunately this specialist version doesn't support nested subclusters, and thus isn't capable of general use.

 

Thus, I would like this capability added to the regular "Variant to Data" primative.