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: 

How to get project instance from VI?

Hi!

There are two questions:

First question:
I have Project A, saved, for example ..\Project A\Project A.lvproj and Project B (..\Project B\Project B.lvproj)
Now I have VI (..\common\MAIN.vi), which used in _both_ projects. Now I will open both projects, and start Main.vi from each one. How can I get (programmatically) from which project VI was started? (reference to this project, or, may be path)

Second question: how can I get then list of libraries (*.lvlib) which are used in each project (without parsing lvproj file)?

Sure, there are must be properties, but I unable to found. 😞

Thank you in advance,

Andrey.

0 Kudos
Message 1 of 7
(7,621 Views)
Hi Andrey,

there are two possibilities to get to know, which VI will be used.
In the VI Properties -> General:
Here you can see, which VI will be used.

With VI Server (function palette -> Application control -> VI Server reference) and a property Node you can read out this path.

But you can't change the path programmatic.


To get a
list of libraries you have to use your Project Explorer. There is "Dependencies"
There is also no other possibility.

Regards
Dippi
0 Kudos
Message 2 of 7
(7,601 Views)
I believe Dippi misunderstood your question, and it is a valid one. You can have the same VI open in multiple contexts, such as two different projects, or one project and the default context (no project). I don't believe there is any programmatic way to determine what context the VI has been launched in. Your best bet might be to create two launcher VIs, one for project A and one for B. Both will launch Main.vi and pass it a string with the respective project name, or perhaps just the correct reference.

Regarding your second question, you can indeed get a list of all child items in a given project. Start by taking the project reference and getting a reference to all the Targets (such as My Computer or your RT Targets). Index out the one of interest (My Computer will be the first target in the array). Then use a property node on the target reference to get the Children[ ] array. I'm not sure if there are specific properties to tell if these children are libraries or not (you can tell if they're VIs or variables, for instance). But you could probably just check the names of the Children for the .lvlib extension. Shouldn't be too hard...

Let us know how it comes along. Good luck!
Jarrod S.
National Instruments
0 Kudos
Message 3 of 7
(7,584 Views)
Actually, come to think of it, there might be one tricky little workaround that would help you figure out which context the VI was launched in (which project the VI was launched from).

You could have Main.vi navigate through the one of the projects (A or B) in the manner I described above and try to find a reference to itself. Take that VI reference and probe its execution state. If it's Running, you'll know you have the right project. If it's Idle, you've got the wrong project. Seems like it should work, but I've never tried it. Honestly, the launcher VI might save you a lot of trouble.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 7
(7,582 Views)

The attached zip demonstrates what I think you are after.

UN zip the attached and open both projects.

OPen and run VI_1.vi and VI_2.vi from both projects at the same time.

They will each present the sub-VI shown to demonstrate where and how they were called.

Have fun,

Ben

Message Edited by Ben on 12-16-2006 03:53 PM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Download All
Message 5 of 7
(7,566 Views)

Thank you, Ben!

This one exactly what I needed.

best regards

Abdrey.

0 Kudos
Message 6 of 7
(7,537 Views)

You are welcome. What was the qurstrion

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(5,333 Views)