LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Distributing objects programmtically

I have a number of buttons, which are made visible or invisible at runtime. I'd like the visible buttons to be evenly distributed. Is there a simple way to programmatically achieve the same results as using the "Distribute Objects" items in the menu bar? Maybe by passing in an array of references to a function? 

 

I know I can accomplish this with property nodes and a little bit of math, but I wanted to see if something already exists. 

0 Kudos
Message 1 of 7
(3,008 Views)

You might check the LabVIEW Tools Network.  I did look in OpenG, and didn't find it, but there are others ...

 

Otherwise, it's Property Nodes and A Bit of Math.

 

Bob Schor

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

Any time I need to have a bunch of buttons in a grid on the UI I think of using arrays of buttons.  There are limitations that need to be worked around, like how array elements can only vary by their value and not properties, but it is more manageable and scaleable.

Message 3 of 7
(2,972 Views)

@buttersworth wrote:

I have a number of buttons, which are made visible or invisible at runtime. I'd like the visible buttons to be evenly distributed. Is there a simple way to programmatically achieve the same results as using the "Distribute Objects" items in the menu bar? Maybe by passing in an array of references to a function? 

 

I know I can accomplish this with property nodes and a little bit of math, but I wanted to see if something already exists. 


The "Distribute Objects" method only works on a VI that is in edit mode; it won't work on a running VI.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 7
(2,956 Views)

It's good to check for a canned solution. Even better to take a shot at coding it.

 

Start by placing all of the buttons at the same location (to make life easier).

(Set all Left and Top Position values to the desired location for the Upper Left button.)

Then loop through the references adding a Column offset (Left) or a Row offset (Top) after setting each button.

 

You will need to use shift registers to keep your current Left and Top values.

I find it easier to use two nested For Loops (Outer for Rows, Inner for Columns - with "moves" only in the Inner loop).

steve

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
Message 5 of 7
(2,943 Views)

@stevem181:

 

I like your method, and if I were the Original Poster, I would mark it as "The Solution) (hint to Original Poster -- read this sentence!).  It is simple, elegant, flexible -- "Who could ask for anything more?" (as the Song Says).

 

Bob Schor

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

Thanks for the suggestions everybody. For my application, I always want the buttons spread out over the same area (ie the space between them changes depending on how many are visible). And I did want the buttons to have different properties. So it ended up just being a little bit of math and property nodes. Maybe if I find myself with some free time I'll make a library to share that mimics the Distribute Objects tool. 

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