LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to tell if top level vi is loaded from a project?

Solved!
Go to solution

The question has to do with the Application Directory VI.

 

The help file says:

If you call this VI from the development environment and the VI is loaded in a LabVIEW project file (.lvproj), this VI returns the path to the folder containing the project file. If the project is not saved, this VI returns <Not a Path>.

 

If the top-level VI is not loaded in a project, the VI returns the path to the directory containing the top level VI. If the VI is not saved to disk, this VI returns <Not a Path>.

 

Is there a way to programmatically check if the top level vi was loaded from within a project?  That way I could adjust the path for either case.

 

I have a project that is still in development but currently being used that loads a configuration file.  I open the program using the project but the user will open it from a desktop link to the VI for now.  I know there are a few other ways around this, but I thought I would ask because I am curious.

 

Bryan

0 Kudos
Message 1 of 13
(1,837 Views)

I'm not sure where, or if, this is documented, and also am unsure if it is a Fluke or a Feature, but I've done the following successfully:

  • In my Project, I create a physical and (Project) virtual folder called "Data".  I use this Data file as the top-level folder for the Data I use in my Project (reading or writing).
  • When I do a Build, the Build creates a Data folder, "findable" from within the Project (using Project-relative paths).  If you have files you need to Read from this folder, you need to copy them from your Development "Data" folder to your Build Data folder.

This doesn't directly answer the question you asked, but it may help you "do it another way".

 

Bob Schor

Message 2 of 13
(1,819 Views)

Thanks for the additional info Bob.

0 Kudos
Message 3 of 13
(1,801 Views)

You could do something like this to see if the project in question is open. If the VI is running and the project is not open, that's basically a guarantee that it was loaded by itself rather than from the project. Unless of course he has a project with the exact same name open.

Spoiler
snippet.png

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 4 of 13
(1,795 Views)

@FireFist-Redhawk wrote:

You could do something like this to see if the project in question is open. 


 

Or slightly simpler.

 

altenbach_0-1599155444593.png

 

Message 5 of 13
(1,773 Views)

Could it be this simple?

 

In Project.png

Message 6 of 13
(1,711 Views)

I get a Not a Refnum when running that without a project open. So you'd have to add a little something something...

Spoiler
FireFist-Redhawk_0-1599219699157.png

 

Plus that would start behaving a little weird with multiple projects open.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 7 of 13
(1,698 Views)

wiebe@CARYA wrote:

Could it be this simple?

 

In Project.png


Interesting, but I have not enabled scripting yet.  I should probably start looking into what scripting has to offer.

0 Kudos
Message 8 of 13
(1,694 Views)

@FireFist-Redhawk wrote:

I get a Not a Refnum when running that without a project open. So you'd have to add a little something something...


Ah, didn't test that. I did remove it from the project I made it, and got the "Main Application Instance".

 


@FireFist-Redhawk wrote:

Plus that would start behaving a little weird with multiple projects open.


I don't think so. You'd expect it to return one of the open projects if the VI is not in a project, but you'll get "Main Application Instance" instead.

0 Kudos
Message 9 of 13
(1,691 Views)
Solution
Accepted by topic author _Bryan

@FireFist-Redhawk wrote:

Plus that would start behaving a little weird with multiple projects open.


It does get weird.

 

I got "Main Application Instance", but only because the project was not active. So it worked coincidentally.

 

How about this (even simpler):

 

In Project 2.png

 

Getting the name of the project would be trivial, but the goal as I get from the thread title is to know if the VI runs in a project or not.

Message 10 of 13
(1,685 Views)