UI Interest Group Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Control/indicator creation at run time (dynamic control creation)

I want to know if it is possible in Labview to dynamically create controls/indicators at run time.  I have been looking around NI site and this UI group, and haven't found an answer to this so I though I would ask here.  I would like to select a number of data channels (from another screen) and display the channels that are selected in a nice grid.  When I select a different number of channels the controls would auto resize to fill the VI as shown in the 2 pictures. 

I know I can create a number of controls and hide and show them based on the number of channels, but I would like to be able to create controls/indicators as I need them since I don't know how many channels might be on the screen because they selected at run time.  I also know that scripting can create controls dynamically, but scripting doesn't work when an EXE is built.  Is there another way to dynamically create controls?  Can it be done with LVOOP classes somehow?

Thanks!!

new vlis gui 1.JPGnew vlis gui 2.JPG

0 Kudos
Message 1 of 16
(26,492 Views)

You can actually use VI scripting to create or modify a vi and then dynamically load that vi into a subpanel in an exe.

I have loaded non-exe VIs into subpanels of executables, it works fine.

Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
Message 2 of 16
(11,092 Views)

Another solution would be to have the control as a separate VI itself. Dynamically load that, and use Win32 APIs to make the Top Level VI as Parent, with the controls as child (GetWindow and SetParent functions). You would need to use CLFN nodes with win32 calling convention (from what I know, since NI optimized the compiler, it won't correct the calling convention itself. So be sure you keep it as win32 calling convention else LV will crash). Once this is done, you can reposition the controls, using Win32 functions again. Search MSDN for the functions to reposition the controls.

- FraggerFox!

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
Message 3 of 16
(11,092 Views)

This particular problem is easily solved using a 2D array of clusters, each cluster containing a string (channel label) and numeric (PSIG value).  You can use VI server calls to show more or less of the array.  You can customize the array elements and the array itself with the control editor, if you want more space efficiency than the default.

This design will also force you into a better back end design which scales with an arbitrary number of channels (assuming you do not already have it).

Let us know if you need more help.

0 Kudos
Message 4 of 16
(11,095 Views)

TroyK wrote:

You can actually use VI scripting to create or modify a vi and then dynamically load that vi into a subpanel in an exe.

I have loaded non-exe VIs into subpanels of executables, it works fine.

TroyK,

I didn't think you could run a script without the development environment.  I will not have the development environment on the machines I distribute the EXE onto, only the Labview RTE.  Please let me know if I am wrong.

Thanks!!

0 Kudos
Message 5 of 16
(11,092 Views)

DFGray wrote:

This particular problem is easily solved using a 2D array of clusters, each cluster containing a string (channel label) and numeric (PSIG value).  You can use VI server calls to show more or less of the array.  You can customize the array elements and the array itself with the control editor, if you want more space efficiency than the default.

This design will also force you into a better back end design which scales with an arbitrary number of channels (assuming you do not already have it).

Let us know if you need more help.

DFGray,

This is a good idea, but there is another issue that I didn't mention in my original question.  I need to be able to change the Units Of Measure by clicking on them. In otherwords, when I click on PSIG, it will change to PSID, inH2O, etc. then back to PSIG.  I don't know if I could do that in an Array/cluster configuration without a lot of math to see where the "click" was placed, and then telling the BD to do the proper conversion.  I will have to think on this some more (Text ring maybe?).

0 Kudos
Message 6 of 16
(11,095 Views)

FraggerFox wrote:

Another solution would be to have the control as a separate VI itself. Dynamically load that, and use Win32 APIs to make the Top Level VI as Parent, with the controls as child (GetWindow and SetParent functions). You would need to use CLFN nodes with win32 calling convention (from what I know, since NI optimized the compiler, it won't correct the calling convention itself. So be sure you keep it as win32 calling convention else LV will crash). Once this is done, you can reposition the controls, using Win32 functions again. Search MSDN for the functions to reposition the controls.

- FraggerFox!

Wow....

I have never used the Win32 APIs in Labview.  I will have to read up on this, it is completely new to me.  This sounds more of what I had in mind with my design, but a lot more complicated than I thought.  What is CLFN?

Thanks!

0 Kudos
Message 7 of 16
(11,092 Views)

Oooh. I didn't realise scripting couldn't be used in an executable. This puts the brakes on my project to create FP controls on the fly.

0 Kudos
Message 8 of 16
(11,095 Views)

Adding a text ring for the units should do what you want to do.  You can use an event structure to determine when something has changed in the array.  Unfortunately, the event will give you the old and new values, but not which element changed (although a comparison between the old and new will get you this info).  Given which element changed, you can then change any other info in the array element.

Be sure to use the In Place Element structure when manipulating array elements so you don't make copies.

Message 9 of 16
(11,095 Views)

Ken McMullan wrote:

Oooh. I didn't realise scripting couldn't be used in an executable. This puts the brakes on my project to create FP controls on the fly.

Ken,

I am not totaly sure on this, but from working with and NI App Engr he was able to get some scriping to work in an EXE, but he had to use the DCS RTE which is an extra package from NI.  I am not sure the DSC RTE would have all the scripting features either, but it did have some.

0 Kudos
Message 10 of 16
(11,095 Views)