取消
显示结果 
搜索替代 
您的意思是: 

VI Scripting - Nested Case Structure

已解决!
转到解答

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 项奖励
1 条消息(共 7 条)
5,222 次查看

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.

2 条消息(共 7 条)
5,201 次查看
解答
已被主题作者 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

3 条消息(共 7 条)
5,178 次查看

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?

0 项奖励
4 条消息(共 7 条)
5,171 次查看

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.

0 项奖励
5 条消息(共 7 条)
5,167 次查看

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 项奖励
6 条消息(共 7 条)
5,161 次查看

Thanks a lot for that example!!!

That helps me a lot to solve my issue.

0 项奖励
7 条消息(共 7 条)
5,138 次查看