LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating and destroying elements at runtime

Hello,

 

I am new in LV. I want to know how I can create and destroy elements while my app is running. Eg. dynamiccally arrange a set of controls.

 

0 Kudos
Message 1 of 7
(2,442 Views)

When you say destroy, do you mean remove from the program entirely?

 

Or perhaps you mean hide from view so that the user does not see them? Or maybe rearrange them on screen so that they look different?

 

The property node for visible lets you show/hide controls and indicators, and the positions can also be controlled by property nodes. At a guess this is probably what you are trying to achieve.

 

Ian

0 Kudos
Message 2 of 7
(2,436 Views)

I want dynamiccally create a tree of devices and according to a different situation which the program may find at its start a different number of objects should be created. Later on the number of objects and its position within the tree should be possible to alter. So I do not only need to control the visuability property of some controls. I want to add and remove objects completely.

0 Kudos
Message 3 of 7
(2,431 Views)

You could look into scripting to programmatically create LabVIEW code. However, you said that you are new to this, so I would recommend getting the hang of the basics first before trying to master scripting.

Think carefully about what you are trying to achieve with the user interface, do you really need to fully remove objects? What is wrong with hiding them from view and replacing them with others?

0 Kudos
Message 4 of 7
(2,426 Views)

There is nothing wrong but it is a more static approach. My software does not really know about the structure and number of objects it will find at start time (e.g.). So from the view of a text based programming language I first would create my relevant objects according to the conditions I find. Now I have the impression that in LabView it would be better to create a bunch of objects during designtime and hide all the ones I don't need. What if I detect I will definitly need more as the previous defined ones. If I now have approx.100 objects in the layout of LV, it maight be rather unclear. I also want to use one base object for every new instantiated object. Is that possible in that way?

0 Kudos
Message 5 of 7
(2,419 Views)

 


@npci wrote:

 I also want to use one base object for every new instantiated object. Is that possible in that way?


 

If I understand you correctly you could use typedefs.

For example you could create an array of typedefined clusters. Each cluster could be a combination of items (controls, indicators etc). If these are in an array you can dynamically add or remove them by changing the size of the array.

The typedef is your 'base' object and allows you to modify your 'base' without breaking other parts of your code later on.

It would be relatively straightforward to create/destroy the elements of the array (i.e. add or remove the combinations of controls/indicators). You could also choose to display individual items by indexing the array to pull out particular clusters. This would allow you to programmatically allocate space at runtime.

 

If the user interface is important, you'd need to excercise some care in how all these parts are displayed. If the user interface is not visible you can just store your objects in the array and access them as you wish.

 

If memory serves me, Ben has written several posts on things like this. Searching some of his posts could serve you well.

0 Kudos
Message 6 of 7
(2,417 Views)

To recap, you want to dynamically create a tree of devices and create a UI which allows easy control of those devices.  And you are a new LabVIEW user.  I have done things like this.  Things you should avoid:

 

  1. Anything involving scripting - this will require a development version of LabVIEW to run (you need a compiler) and, in my experience, there is almost always a better, faster, more efficient way (which is sometimes not very obvious).
  2. Massive number of controls you show and hide - this can get very slow and there are better alternatives
Possible solutions:
  1. Tree control with subpanel - use the tree control to keep track of your devices as you create them and the subpanel to host a configuration VI for each.  You will need a central server to maintain the info.  I would highly recommend the use of classes to make your life much easier (and your learning curve steeper, if you have never done object oriented programming before).
  2. Picture control - you can draw anything on a picture control, including any sort of control you can imagine.  The picture control comes with a relatively complete set of UI events.  This is a much harder approach than 1.
The LabVIEW help is a good starting point for anything you are unfamiliar with.  Next, try searching these forums.  There are numerous examples of tree controls, classes, subpanels, etc.  I just dumped an awful lot of info on you.  Take the time to work through it with simple examples before designing your final code.  If you run into problems, let us know.

 

Message 7 of 7
(2,407 Views)