LabVIEW APIs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace VI Programmatically

Solved!
Go to solution

Hi Experts,

I have created a folder of VIs it is a set of State Machine VIs. ( Global Var, Typedef Controls, VIs).

I would like to make a copy of this folder and rename the prefix of the VIs. For example: SSM - Main -> NewName -> Main.

My problem is the following. When I renamed ( VI method - Save) them, and placed into my project, The renamed VIs looking for the old name dependencies. Is there any way to make my VIs find the renamed subvis?

For example:

  • Programmatically replaca VIs ( By Scripting )

Any Ideas? Thank you!

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
Message 1 of 12
(11,439 Views)
Solution
Accepted by topic author D60

Sorry, Solved!

Next time I will be more careful.

Untitled.png

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
Message 2 of 12
(7,988 Views)

The other simpler way to do this is just to do your save-as new-name.vi starting from the bottom of your VI hierarchy and work to the top.  If you rename a VI with it open, (not just rename in the operating system), then LabVIEW updates the callers, then when you rename and save them the already have the dependency reference changes for their subVIs, etc, etc til you save the topmost VI last.  I'm not positive, but I think I recall seeing a couple of utility VIs either here or over on LAVA.  It is pretty easy to do with VIs in the OpenG toolkit without resorting to your own scripting.

Message 3 of 12
(7,988 Views)

Thank you for your post. It really makes my life much easier. I will make some tests and write back the results!

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 4 of 12
(7,988 Views)

Hello,

I made some tests, here are my results:

I have a Typedef.ctl referred in many VIs.  Let's tha caller name is "Caller.vi" Here is my Save BD:

Copy.png

So, When the Caller.vi has opened Front panel, the save method do what I really want. Rename the Typedef.ctl to new name and the Caller is updated with the renamed Typedef.ctl.

Anyway, When The Caller.vi is not opened, ( not in memory ) the result is different. New Typedef.ctl is created but the caller has not been updated with the new name.

So my conclusion is the following:

If I want to achive my goals ( described in the first post) I have to start the rename procedure with the bottom of the hierarchy ( as you said ) but the caller must be in memory in order to relink its dependecies to the new name.

Please correct me if I am wrong!

So, considering this circumstances I think the scriping solution could be better, than to write a in-order tree traversal algorithm along the call chain, load parent VI into memory, and rename its childer VIs.

Any opinion?

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 5 of 12
(7,988 Views)

That is exactly how LabVIEW has worked since the beginning. VIs (and CTLs) are linked together at load time based on their name (and path) and if you rename a VI in memory all it's callers in memory are updated to reference that new VI. And if you save them they will refer to this new VI or CTL from thereon.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 12
(7,988 Views)

to answer your statement/question that scripting is better.

to get all the information about vi's and ctrls into the scripting is more work than traversing a fully loaded "tree.vi" so NO scripting for this case.

greetings from the Netherlands
Message 7 of 12
(7,988 Views)

Dear Albert.Geven,

Thank you for your reply. All comments are welcomed!

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 8 of 12
(7,988 Views)

I have found this link: https://decibel.ni.com/content/message/18955#18955

Antoine Châlons first post seems very interesting,

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 9 of 12
(7,988 Views)

Yes, the upper level VIs need to be in memory for this to work.  I always started with the Top Level VI open, got a reference to it, then iterated down it's callees for "level 2", then got their callees for "level 3" and so on down the the very bottom, then worked back up. 

I should have stated the requirement to be in memory, but I thought that was obvious, sorry.  This technique has been around long before scripting and LabVIEW projects, at least 10 or 15 years. 

Good luck on your project.

0 Kudos
Message 10 of 12
(7,988 Views)