LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI Scripting - Nested Case Structure

Solved!
Go to solution

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.

CaseStructure.jpg

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.

 

0 Kudos
Message 1 of 7
(3,714 Views)

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.

Message 2 of 7
(3,693 Views)
Solution
Accepted by topic author Ralbar

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.

 

Scan for Cases.png

Message 3 of 7
(3,670 Views)

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.Smiley Wink Not sure why you needed a zip?

0 Kudos
Message 4 of 7
(3,663 Views)

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.Smiley Wink 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.

0 Kudos
Message 5 of 7
(3,659 Views)

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.

0 Kudos
Message 6 of 7
(3,653 Views)

Thanks a lot for that example!!!

That helps me a lot to solve my issue.

0 Kudos
Message 7 of 7
(3,630 Views)