04-15-2022 10:25 AM
I have a few clusters that contain data that I am putting in a database using a Python script. I want to label things as they go into the database based off of what the element name in the cluster is and I want to do this dynamically so that if I change the name of the elements in the cluster it will change what I am sending to the python script and go in with the new name. I can not find a way to dynamically create an array or any data structure that holds the name of the elements in a cluster. In short I want to grab a cluster and output some data structure with the list of element names from the cluster. Any information on this would be great!
Thanks!
04-15-2022 11:19 AM
Use the Get Cluster Information VI to get an array of cluster elements and then Get Type Information to get the name of each array element.
04-15-2022 11:19 AM
You can flatten a cluster to JSON or XML and parse the names from there.
04-15-2022 11:29 AM - edited 04-15-2022 11:30 AM
The OpenG toolkit has "Get cluster element names":
Edit: Dang, lots of posts. Use Kyle's suggestion, it doesn't require an external toolkit. I didn't know that one was there.
04-15-2022 01:15 PM
@BertMcMahan wrote:
The OpenG toolkit has "Get cluster element names":
Edit: Dang, lots of posts. Use Kyle's suggestion, it doesn't require an external toolkit. I didn't know that one was there.
Nope, Kyle's method will get a list of datatype names not element names.
Try showing us the BD of the OpenG vi
04-15-2022 01:26 PM
@JÞB wrote:
@BertMcMahan wrote:
The OpenG toolkit has "Get cluster element names":
Edit: Dang, lots of posts. Use Kyle's suggestion, it doesn't require an external toolkit. I didn't know that one was there.
Nope, Kyle's method will get a list of datatype names not element names.
Try showing us the BD of the OpenG vi
Kyle's method returns the same thing OpenG does:
The OpenG method uses a bunch of other OpenG VI's internally, so posting just that one's block diagram isn't very useful. At its core though it uses Variant to Flattened String and parses the result.
04-15-2022 01:41 PM - edited 04-15-2022 01:46 PM
Thanks Bert,
I'll have to submit feedback on the help for Get Type Information.vi.
The help clearly states Name is the Name of the data type not the Lable of the Variant.
04-15-2022 01:50 PM
Yeah, the data type (U8, String, etc) is returned as an enum in the "type" output and the label of the data is given in the "name" output. In the Help file it does specifically say "name returns the name of the data type stored in variant". Definitely not the right language.
04-16-2022 03:58 PM
Since you are passing the data to Python I would recommend flattening your clusters to JSON.
04-18-2022 02:47 PM
Flattening to JSON seems to be the clear answer here.
Note that the label of the cluster itself is not included in the JSON string, though.