11-03-2017 03:48 AM
I want to create and analyze a complex nested case structure programmatically via LabVIEW scripting.
The challenge I am facing is to retrieve/ parse the hierarchy of a previously created nested case
structure.
Based on the example above, is there a possibility to retrieve the information that Case L3 is included in Case L2 and Case L2 is a included in Case L1? The scripting VI "Travese for GObjects.vi" only returns the references of all cases included in the VI but no hierarchy information.
Solved! Go to Solution.
11-03-2017 04:40 AM
This is where recursion (to understand recursion, you must first understand recursion) comes in.
So you have a routine that gets all nodes from a diagram. One of those nodes is a case. A case has a diagram. Parse this diagram to the VI (you are running).
The other way is to work the other way around. Also with recursion...
The case is inside a hierarchy. Get it's owning diagram. This diagram can be either a top level diagram, or a diagram that has an owner (case structure in your situation). This in turn can be a top level diagram or a diagram that has an owner.
The only way to do this without recursion is to get information from each diagram (from a traverse), and link that to the parent or child references.
Since the hierarchy is, well, hierarchical, recursion would make sense for me, but it isn't easy.
11-03-2017 09:00 AM - edited 11-03-2017 09:02 AM
Oh it's not as hard as you think. Yes native LabVIEW recursion could be used (since the 8.x era, and a couple of cheating methods before that) but honestly while loop recursion works just fine. By that I mean use a while loop that does some work which may make more work that will keep the while loop running. For a good example of this look at the Recursive File List function on the File I/O palette. It lists all folders, and then lists those folders, and those folders until it has all files and it does this without having to call itself.
Attached is the case structure code you are looking for. It will create a tree showing all the case structures on a block diagram (example VI included) and then finds all cases in all structures. BTW I love scripting.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
11-03-2017 09:47 AM - edited 11-03-2017 09:48 AM
While loop recursion is much harder to make then normal recursion (for me anyway). Much more code anyway. And less extendable.
But it easier to post since you can make it work with just one VI. Not sure why you needed a zip?
11-03-2017 09:55 AM
wiebe@CARYA wrote:
While loop recursion is much harder to make then normal recursion (for me anyway). Much more code anyway. And less extendable.
Eh it depends on on the developer. I sorta prefer the while loop approach. It is easier for me to understand what is going on rather than to see code calling itself.
But it easier to post since you can make it work with just one VI. Not sure why you needed a zip?
I wanted to include the example case VI. I like being able to just unzip something, hit run, and see results and figured OP might like that too.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
11-03-2017 10:03 AM
Figured out the zip (actually looked into it).
I like the VI recursion, because it plays nice with OO\Dynamic Dispatch. I have a lot of situations (including scripting) where I want a DD VI to call "itself" (the same method but maybe for another object).
For this reason I think VI recursion is a bit more scalable, but probably less intuitive.
11-06-2017 01:24 AM
Thanks a lot for that example!!!
That helps me a lot to solve my issue.