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: 

Create object reference by name

I wish to disable and enable a bunch of controls on the front panel. Instead of creating hard-wired property nodes, I wish to cycle through an array of string names of controls and set the corresponding control's property. Is it possible to create a reference on the fly based on a string? The reference will then be fed to a Property node. Or is there an alternative way for my problem?
0 Kudos
Message 1 of 12
(4,458 Views)
You can get a reference to a vi then get the reference to the front panel of that vi. Using the front panel reference you can get a reference to the front panel controls. This will be an array of references of the front panel controls and you can index each reference to get the properties. Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 2 of 12
(4,458 Views)
OK BJD, that's all swell, but this is still chinese for me.  HOW do I reference all those things ?
 
I have kind of the same problem : I have a bunsh of measurements that I transfer to a VI with a 'label' added to every meausrement (like Temp1 : 20 / Temp2 : 25 ...).  I would like to 'automatically' have the 20 appear in the indicator named 'Temp1' etc, but can't figure out how to reference this.
 
Thanks
 
Jan


Message Edited by Jan145 on 01-08-2008 04:07 AM
0 Kudos
Message 3 of 12
(4,241 Views)

What BJD means is something like what is shown below.  It is not the same, because I "borrowed" it from existing code.

In my example, I am getting the name of each control for every page of a Tab Control.  The image will give you an idea how to proceed.  You can replace Main Tab with This VI and the property node will be for application instead of TabCtl.  And you won't need Page..

Maybe I should do a proper example 😉



Message Edited by JoeLabView on 01-08-2008 08:00 AM
0 Kudos
Message 4 of 12
(4,225 Views)

See the image below for a better example.

This one provides a list of all the controls on the front panel.  See the names of the labels appears in the ArrayofCtrls.

RayR


You can create a subvi of this. Replace ThisVI by a control.  You then wire This VI from the calling VI.  Or, you can get fancy and wire a pathname to the appropriate function which replaces ThisVI in the above example.  You can then obtain front panel listings for other VI's.  The possibilities are alomost endless 😉 

Message Edited by JoeLabView on 01-08-2008 08:11 AM
0 Kudos
Message 5 of 12
(4,220 Views)

Thanks, this helped me in the right direction I guess, but the problem is more like the opposite of what you gave me :

Your vi gives me all the names of all the controls on the front pannel, but what I need is something like "get me control which is called 'Temperature 1' and enter '20' in it".

I'm sure I could do this using your solution, but then I will have to run over all the controls and check if they have the name I'm looking for.  So I guess there must be an easier way ???  I tried by somehow looking in the array of objects, but can't get it right.

Jan

0 Kudos
Message 6 of 12
(4,204 Views)

You need both the array of control references and the array of names as shown in the example.  You can do a search to find the index of the name (thus of the control) which corresponds to the control reference of interest.  With the control reference, you can wire that to a property node and select the function "value" and write the desired value to it. 

You're close..  😉 

0 Kudos
Message 7 of 12
(4,197 Views)
Getting back to your original question, we almost have your solution.  Run the code JoeLabVIEW posted as an initialization step and save the array of references and array of labels (a local shift register is your best bet, but, since this is a lookup table, a global works well also).  When you need the reference to a control, find the control name in the list of labels using Search 1D Array, then use the resultant index to select a reference from your array of references (use Index Array).
Message 8 of 12
(4,181 Views)

You can also pass the name (lable) of the control into the selector of a case structure, and then use the object names as cases.  A default case will cat as a catch-all this is very efficient and scalable if you plan on modifying many controls by name.  This is static though since you cant pass the names of the controls down to a subvi.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 9 of 12
(4,175 Views)
Also recall that is it possible to have more than one control with the same name. The references will be different. If you are going to use a "by name" operation in your program it will be up to the programmer (you) to make sure that no duplicate names exist. If the user interface needs to display the same text for more than one control, then you should display the captions and hide the labels. Make the labels unique and the captions whatever works for the users. Captions can also be changed at run time (for language localization, for example), while labels cannot.

Lynn
Message 10 of 12
(4,170 Views)