LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"How to index a nested cluster?" or "How to get the data out of a variant"?

Solved!
Go to solution

Hello!

I have a nested string cluster with some data. The goal is to use the cluster as template for an INI file. The 1st level element names make the sections, the 2nd level element names make the keys and the data makes the keys's values. Since the cluster is nested it cannot be auto-indexed directly or converted to an array, so I came across type information and variants. As for the names of the 1st and 2nd level I can go like this:

MaSta_0-1678808411597.png

However, the 2nd level element is still a cluster, but loses the data this way. Indicator's "Element" data is empty. If I try to extract the data of element "LOG_PATH" directly from the variant,

it doesn't work because I cannot index the variant. There is a VI to search a variant for attributes (don't know what they are) and to return a value, but it didn't work to find LOG_PATH or GENERAL.

 

Any idea how to get the value "default_log.csv" from the LOG_PATH element out of the variant or cluster? Of course not in the usual way, because this is supposed to be automated in FOR loops since the cluster information array can be auto-indexed.

0 Kudos
Message 1 of 6
(1,207 Views)

We don't you attach your shown VI containing some default data? We don't do well with pictures.

0 Kudos
Message 2 of 6
(1,203 Views)
Solution
Accepted by topic author MaSta

Cast the cluster variant to an array of variants using the variant to data node, then index the element of the array you want. You'll still need the other methods you show to find the item you're looking for, but those methods don't return the data as you noted, so you will need to manipulate your original cluster, sometimes doing multiple to array of variants to get to the depth you want.

Message 3 of 6
(1,195 Views)

There are a variety of (slightly complex and complicated) functions that can "parse" a Variant.  Some are included with LabVIEW, some are in (or used to be in) "Hidden Gems" in the LabVIEW Tools Network (VIPM), and some are in OpenG (also in the LabVIEW Tools Network).  I recall doing something like this within the last 10 years, but am not sure I can find it among my older code.  But it does offer you the possibility of parsing your Variant ...

 

Bob Schor

Message 4 of 6
(1,153 Views)

Wow, I didn't think of that one. 

0 Kudos
Message 5 of 6
(1,127 Views)

I'm not sure I can tell if it'll fit your use case, but I highly recommend you check out a VIPM package I've been using for somewhere near 20 years (if memory serves).

 

It's "MGI Read/Write Anything" which is designed to work on INI files.  But I've also used it with plain old strings (such as for adding metadata into TDMS) by digging down a level or so and using its string-processing subvi's.  If you do that, you may need to discover and work around some of the formatting conventions they use.  Nothing major, but I remember needing a couple little tweaks to get rid of things like extra blank lines or something like that.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
Message 6 of 6
(1,107 Views)