LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically updating elements within library/class not working

Solved!
Go to solution

Hey folks,

 

I have a little annoying problem. where I am running out of ideas on how to tackle it. I have a project wherein lives a class with a few methods and a view ring text controls. From time to time I need to update a two methods and a few controls. For this I have written a VI scripting tool, which updates the VIs/CTLs. Up to here its working nicely. However, replacing the original code within the library is giving me headache. My approach is the following at the moment. I am saving the new vis to a temporary folder. Then I check which of the temporary vis is already existing in the library, removing it from the library and deleting the vi/ctl. Now I am copying the new files from the temporary folder to the libraries location, adding them programmatically to the library, saving the library and the file and all other files that have been modified by this process. But when looking up the results, nothing has changed, since Labview reverted the files to their original state, because they have already been in memory (sic!).

 

I have given a small example of what is happening. The CTL.ctl in the test class shall be replaced by the CTL.ctl in the temporary folder. This is done by the Move files.vi. This needs to be called before having opened the example project, to not having any of the files already in memory. The text rings are differing in their values. I added an additional copy of the control to copy from Temp im the Copy folder, since the control in Temp is getting destroyed during the process.

 

Does somebody have any idea to prevent LAbview to revert the copied files?

0 Kudos
Message 1 of 6
(467 Views)
Solution
Accepted by Dr.Polz.Photonics

Not an easy problem at all, but here is what I would do:

 

1. Create the new VI (Untitled) via VI Scripting.

2. Add the new VI to the library using the "Add Item From Memory" project item method.

3. Save the new VI (with another name than the old VI) to a temporary folder. Now the new VI on disk belongs to the library.

4. Remove the new VI from the library using the "Delete" project item method.

5. Move the new VI on disk and overwrite the old VI (use old VI path as destination).

6. Get a reference to the old VI in memory, call method "Revert VI".

 

This should allow you to regenerate a VI already present in a library.

 

Regards,

Raphaël.

0 Kudos
Message 2 of 6
(440 Views)

Each project has its own context.  Running VIs outside that context has no effect on files open in the project.

If you want to affect items in an open project, find the project's app context and use that when you script.

paul_a_cardinale_3-1721322958685.png  Be sure to close both the project and app references.

 

Other notes:

  • Your diagram isn't terribly messy, but it's got a lot more zig-zags than necessary.
  • paul_a_cardinale_0-1721322703357.png You don't need to wire "This Application" to the property node; that is the default.  Also, there's no need to closing that reference.

     

  • paul_a_cardinale_1-1721322793157.png No need to close a static reference.
0 Kudos
Message 3 of 6
(424 Views)

Hey Paul,

 

thanks for your advice. However, I do not understand fully, where to make use of it. If I open the Project with the invoke node and then try to delete project items from the class, I get an error that the project is locked.

 

Sorry for the cleanliness of the code, I just copied together two subVIs and modified them to make a running minimum example and did not take overly care of cleanliness. Nevertheless, thanks for your hints regarding closing the static references.

0 Kudos
Message 4 of 6
(372 Views)

@Dr.Polz.Photonics wrote:

Hey Paul,

 

thanks for your advice. However, I do not understand fully, where to make use of it. If I open the Project with the invoke node and then try to delete project items from the class, I get an error that the project is locked.

 


Hmm.  I've never encountered a locked project.  I don't know what would cause that.

0 Kudos
Message 5 of 6
(354 Views)

 

Hey Raphaël,

 

even though it's counterintuitive on the first sight, Revert VI is doing the trick. I added this to my script after copying the new files to the class folder overwriting the old VIs.

 

DrPolzPhotonics_0-1721989958789.png

 

So what's happening here, is that Labview restores the new VIs to the state of the old VIs, since they were already in memory. Revert VI now restores the content of the new VIs, giving me what I want. I'll attach a modified, working version of the initial sample project, for future use, if somebody needs it. Thanks

0 Kudos
Message 6 of 6
(342 Views)