From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Specific References for all Controls

Solved!
Go to solution

Using slightly modified code from here, I am generating an array of all control references on my main front panel which is then passed through to a number of subVIs. Although this functionality does work, it would be preferable to get specific references to the controls (for example, Boolean RefNum instead of Control RefNum). 

 

Getting these specific references seems possible using To More Specific Class and Class Specifier constants. However, data storage becomes an issue because I can no longer use arrays (as they are a different data type). I am not sure if there is another way to pass this data on. I have experimented casting the RefNums to Variants, but to get the data from the variant, I have to know what RefNum type I am expecting which sort of defeats the purpose of doing this in the first place.

 

A secondary problem is keeping the names of the references. The Control RefNums do not have names associated with them nor do I know how to assign names to them. I've again tried using variants and using the OpenG Set Data Name function, but this crashes LabVIEW without any indication of why.

 

I've attached a version of my code that tries assign names using OpenG Set Data Name and build a variant array. To run it, simple add the VI as a subVI to a VI that has some boolean controls on the Front Panel. Apologies for the rough state of the code - I'm still in the process of figuring out how to make it work so things are a bit messy.

0 Kudos
Message 1 of 14
(6,127 Views)

I may have a couple possible ideas but I think we need to know a little bit more about what you are trying to do with these references.  What is the end goal of your application?  How are you going to use these references in your subvi's?  Some more information will help because there may be a less complicated approach to what you want to do.

------------------------------------------------------------------------------------------

Jon F.
Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 14
(6,100 Views)

There are two main functionalities I'm looking to implement: controlling front panel displays from subVIs and controlling either event structures or case structures in subVIs based on user input to the main front panel.

 

The first functionality is actually fairly easily done using control references. I can, for example, change the tab structure tab by writing a value to the tab control or disable certain controls. For this scenario, using control references works well.

 

The second case, controlling case structure or event structures in subVIs is a bit harder (event structures especially). For example, I have a button that the user presses to display a path on a Google Earth ActiveX window. The event structure driving this exists in a subVI, so I need to pass in the reference to that boolean. In the current iteration of the code, this is done by creating a reference to that boolean (Right click -> Create -> Reference) that is passed through to the subVI. In an ideal case, I could pass in a list of all controls with explicit types so I don't need to get all control references and get specific RefNums for those same controls.

 

Does that make a bit more sense?

0 Kudos
Message 3 of 14
(6,094 Views)

This does clarify a few things.  Have you considered using the initial array of refnums and creating another array with the names you assigned that you could pass with them?  This way you would have your array of control refnums, and an array with the corresponding names at the same indexes.

------------------------------------------------------------------------------------------

Jon F.
Technical Support Engineer
National Instruments
0 Kudos
Message 4 of 14
(6,063 Views)

That is what I am currently doing. However, this method does not work as well for two reasons:

  1. When setting up event stuctures, there are no names associated with the control refnums, meaning it is difficult to tell which event case is which.
  2. I would prefer to work with type specific refnums in most cases (boolean, etc) rather than generic control refnums. It means that there is less processing necessary. For example, right now to read values from the controls, I need to use the get variant data function and program in the type of control. Ideally, this data would be stored with the refnum itself.
0 Kudos
Message 5 of 14
(6,053 Views)

I've been doing a bit more searching and found this forum post. This is what I'm looking to do, but I'm hoping there is a way to get all of the references without needing to hardcode everything as was done in the posted solution.

0 Kudos
Message 6 of 14
(6,034 Views)

Use the subVI Traverse for GObjects.  You can find if if you type that name into the Quick Drop dialog.  It is inteneded for scripting.

0 Kudos
Message 7 of 14
(6,027 Views)

This gets me closer. However, it still relies on casting to a more specific type to get full access to the properties and methods available for the particular control. It also removes the label.text associated with the reference. If possible, I'd like to keep the label associated with each reference to make generating event structures a bit cleaner.

0 Kudos
Message 8 of 14
(6,020 Views)
Solution
Accepted by topic author martian101

I don't know if you'll get much better.  There is really no way I know of to have some fully flexible way of building named clusters of references based on any given front panel set you feed to it.

 

I tend to do things the manual way (as there are also a bunch of references to front panel elements I wouldn't need).  I would do all the bundling work in a subVI.

 

I'm attaching a zip file that contains the key VI's (unless I missed something) on the first project where I really tried to abstract out the reference building.  The files are LV9.

 

On my main VI, I have the subVI called Build UI References early in the VI during an initialization phase.  I pass the reference to the main VI into that subVI that builds all the references.  I worked it as a master cluster that contains elements that are arrays of references of related controls.  It uses another subVI called Get References and Label Names that I created to help find controls.  I still need to use More Specific Class to get the property references, but I don that only once at the beginning.  I then pass that cluster wire out and to anywhere in my VI that would need access to the references for front panel elements.

 

I use arrays of strings to supply the names I need to build and bundle the references.  This lets me ignore controls I don't care about.  The disadvantages to my system is that if I change the name of any control, I need to update the name within this subVI.  And if I want to add any controls, not only do I need to add the label names for the searching functions, I also need to update my typedef cluster (and you definitely want this to be a typedef) to add a spot to store the new reference.

 

I hope this gives you some ideas.  It worked for me and I will likely use the scheme on another project (or even rewrite past projects using this scheme.)  If there are any ideas for improvements, I'd be happy to hear them.

Message 9 of 14
(6,012 Views)

Thanks. I've accepted yours as the solution and will proceed with it for now, but hopefully will come across a slightly more robust solution.

 

0 Kudos
Message 10 of 14
(6,001 Views)