LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting: Detect if a Library is Locked

Solved!
Go to solution

The situation:

  • I'm writing a scripting tool that operates on a class in a project
  • Sometimes LabVIEW locks libraries, saying that they are open in other instances of LabVIEW, in which case my scripting code would fial

 

Two questions:

  1. There must be a way to detect that a library is locked, but I don't see any property for that; who knows how to do that?
  2. It feels like LabVIEW often locks libraries for no reason. For example, there's only one project open but the library is locked. I open the library, which unlocks it, then close the library and it remains unlocked. Who knows why and/or tips to avoid this locking behavior?

 

__PRESENT

0 Kudos
Message 1 of 5
(396 Views)
Solution
Accepted by topic author 10Things_Rob

Like in the other thread about moving things, there is a Locked property node:

 

Kyle97330_0-1745267849864.png

 

The way to get this visible is nearly the same as in the other thread:

 

You can make this (and a LOT of other stuff, most of which you won't need) visible by changing your LabVIEW.ini file to include this line:

SuperSecretPrivateSpecialStuff=True

 

Alternately, to add it without changing your INI file:

1. Drop an invoke node for the Library (or LVClassLibrary) class on one of the other properties (any). 

2. Make sure it and nothing else is selected on the block diagram.

3. Press control-space to bring up Quick Drop

4. Wait for a bit if this is the first time you have opened it

5. Type in "Locked"

6. Press Control-Shift-B

 

It should then alter that invoke node to be a "Locked" property.

 

However, the functionality of this looks a bit weird, as it's an I32, not a Boolean.  It's also writable.  I advise you to only read from it, as writing to private nodes like this could cause problems.

 

The other thing I would mention is that sometimes to make things usable you need to make sure that you're opening it using the correct Application instance.  If you get locked libraries, I would try making sure that you're passing a "This application" reference around to make sure it is always trying to open it under the same reference.

Message 2 of 5
(372 Views)

Hi,

 


@10Things_Rob wrote:

2. It feels like LabVIEW often locks libraries for no reason. For example, there's only one project open but the library is locked. I open the library, which unlocks it, then close the library and it remains unlocked. Who knows why and/or tips to avoid this locking behavior?


A class will be locked as soon as it is loaded in more than one context ( = application instance).

 

In a project, a class is already loaded in the application of its owner target (typically "My Computer"). If you then open a refnum to the class programmatically from one of your tools (from the Tools menu, from a Project Provider, ...) without wiring the application refnum input, it will use the tool context and then lock the class.

 

So you have to find the owning target of the class first, and use its associated application to open the class refnum. Class ProjectItem has a subclass "TargetItem", which has property "Application". It is a refnum to the context of the target.

 

Regards,

Raphaël.

0 Kudos
Message 3 of 5
(352 Views)

I accept and appreciate what you're saying.

 

What I am seeing is:

1) Launch LabVIEW

2) Open Project (which only has one target)

3) Class in project is locked.

4) Open Class

5) Class is unlocked

6) Close Class

7) Class remains unlocked

 

This is all manual operations, nothing at all to do with scripting

__PRESENT

0 Kudos
Message 4 of 5
(280 Views)

Turns out, there is ALSO a Boolean, which does not allow write-access.

It seems from experimentation that they indicate the same value.

 

10Things_Rob_1-1745353823282.png

 

Also, from experimentation, opening the reference to the Project does not unlock it; only doing that manually from the project window unlocks it. Must be something happens as part of the process of opening the window that causes it to re-evaluate whether it should be locked.

__PRESENT

0 Kudos
Message 5 of 5
(279 Views)