07-02-2015 08:59 AM - edited 07-02-2015 09:00 AM
I have an array of variables, I would like to essentially unbundle that array to named variables.
I believe the only way of doing this is by converting the array to cluster (besides removing each element one by one)?
Is what I have done below the best way of doing it? seems a bit weird having to unbundle and rebundle by name.
comments appreciated.
Solved! Go to Solution.
07-02-2015 09:23 AM - edited 07-02-2015 09:26 AM
You can use the Array to Cluster node to do the conversion for you. The tricky part is the name matching. If the first element in your cluster is always going to be the first element in the array, it works fine. But as soon as you add a new cluster element, you will run in to trouble. The Bundle by Name eliminates this problem by using the names and is really the only way to make sure your names always match up with the right array element.
To clarify, you don't need the Bundle by Name to wire the bundle straight in to the indicator you have, but in order to get those names in the Unbundle by Name node, you do.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
07-02-2015 09:26 AM
Also, you should make that cluster into a Typedef, for future expansion.
07-02-2015 09:28 AM - edited 07-02-2015 09:29 AM
Thanks for the reply.
The first array element will be the first cluster element, and the rest of the elements will be in the same order for each.
How can I use the array to cluster to add names to the cluster elements?
Is there a way to add names to the array elements?
07-02-2015 09:31 AM
Your problem code is actually right before the red square. Instead of the "array-to-cluster-unbudle dance", you should simply use a plain index array resized for the same number of outputs. same functionality, less convoluted.
Your wiring is a bit of a mess and it is hard to tell if the order of elements in the array is the same as in the cluster. Maybe a simple typecast to the cluster would work.
07-02-2015 09:31 AM - edited 07-02-2015 09:33 AM
[Deleted]
Altenbach to the rescue!
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
07-02-2015 09:36 AM - edited 07-02-2015 09:37 AM
Here is what Altenbach means. This is what you want, right?
Edit: shoot you can even get rid of the Array To Cluster node in there and just type cast the array.
Make sure you Type Def your cluster so you can change those names in the future to keep your code consistent.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
07-02-2015 09:36 AM - edited 07-02-2015 09:37 AM
07-02-2015 09:41 AM
Note that typecasting has no error checking, so you better make sure that the sizes and types match or you get garbage, of course.
07-02-2015 09:44 AM
thank you all, this was what I was after.