LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Sub Panel to center on VI it is showcasing?

Solved!
Go to solution

That's basically it. I have a main VI and in it is a Sub Panel window that shows another VI through it. But when it comes up, the Front Panel of the shown VI is off center and I have to readjust it with the scroll bars that appear on the sides of the Sub Panel. 

 

I looked this up and someone said that the Sub Panel Invoke Node has a property which can direct it to center on the shown VI, but I have yet to find it. Is there another way?

0 Kudos
Message 1 of 11
(3,965 Views)

hi

  You can use the Window Run-time Position property of the shown vi(vi need to be inserted into the sub panel) from the VI properties.

regards

Senthil

0 Kudos
Message 2 of 11
(3,957 Views)

Okay, I'll give it a try.

0 Kudos
Message 3 of 11
(3,950 Views)

Here's what I do --

  1. I put a sub-Panel on my Main VI's Front Panel.  I size it appropriate to the Main VI (with some thought to the proportions of the sub-VI Front Panel that you want to see inside it).
  2. In my sub-VI, I create a Front Panel Decoration that's the same size as the Main's sub-Panel.  Inside this Decoration, I arrange the Controls and Indicators that I want to show when the sub-VI's Front Panel is visible.  In particular, if the sub-VI has Error In and Error Out (as it should), these are placed outside the Decoration.
  3. Using the VI Package Manager (which is installed "by default" with most recent versions of LabVIEW), I install the OpenG Toolkit.  Once installed, I look in the OpenG Application Control sub-Palette and put "Fit VI Window to Largest Decoration" as one of the first functions to be executed.

When my Main VI calls the sub-VI, the sub-VI executes "Fit VI Window to Largest Decoration, which "snaps" the Front Panel to the borders of the Decoration (I usually use Raised Frame), so what appears in the sub-Panel is the Frame and whatever I've placed inside it.  It fits size-wise (because I made the Decoration the right size) and fits in the Window as I designed when I made the sub-VI's Front Panel.

 

Another "trick" you can use to keep your controls/indicators/decorations "aligned" on your sub-VI is to band-select them then choose to "Group" them (you know the little alignment controls at the top of the Front Panel and Block Diagram windows?  The third one has the "Group" command).  Now they all will "move as a unit".

 

Bob Schor

Message 4 of 11
(3,912 Views)

Thanks for the suggestion, but when I implemented the Fit to Window function in the Sub VI and then ran the Main VI, it gave me this error: Error 1148 This Property is read only while the VI is in a Sub panel.

 

I think I ran across this error before and have never figured out how to fix it. But the Fit to Window Function returns no error when I run the Sub VI by itself. Maybe there's a clue to the fix in that?

0 Kudos
Message 5 of 11
(3,882 Views)

I looked it up and Error 1148 means - This property is read only while the VI is in a subpanel. 

 

Is there any way to get around this?

0 Kudos
Message 6 of 11
(3,897 Views)

What property?  Be more specific.  Post code. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 11
(3,891 Views)

Well, that's just it. The Error itself is very vague. As far as I know I'm not using any property nodes or anything. 

 

As for the code, my program is pretty basic. I created a Main Vi with a Sub Panel window to show a Sub VI. Then within the Sub VI I applied a function called Fit VI Window to Decoration, which basically shrinks the the Sub VI's Front Panel to to the size of the largest "decoration" that you have on the Front Panel. So if you draw a big rectangle around everything then the Front Panel will shrink to fit the parameters of the rectangle.

 

Anyway, it seems the problem has something to do with that Fit VI to Decoration function. If I take it out I don't get the error anymore. And oddly if I run the Sub VI by itself, not through the Main VI, then the function gives no error whether it's active in the Sub Vi or not.

0 Kudos
Message 8 of 11
(3,884 Views)

This message was actually broken off from another thread that provided more information.  Since the important information is in the first thread, I'll merge the two threads together.

0 Kudos
Message 9 of 11
(3,877 Views)
Solution
Accepted by topic author ShogunOrta

So the technique is to start the sub-VI before you put it in the sub-Panel.  

 

I've used two different methods to do this.  In one, the code that ran in the sub-Panel was coded as an Action Engine, with an Init Action that had the Fit to Largest Decoration in the code.  I called the Action Engine with Init, then wired its reference to the Insert VI sub-Panel function.  In the other, the code was written as a Message Handler, "spawned" using Start Asynchronous Clone (to get it running), either set to self-initialize or called from the Host with an Initialize Message, and then wired (via its reference) to the Insert VI function.

 

Bob Schor

0 Kudos
Message 10 of 11
(3,863 Views)