From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW APIs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to rename a project item with scripting?

From the project explorer it's easy to rename a project item (right click >> Rename), I even found out that we can "move the file on disk and rename at the same time", that's cool!

I've been trying to rename different project items with the scripting method "Rename" for wich there is just one string input "name".

It works fine for virtual folders, but when the project item that I try to rename is a VI I always get "error 1"... Why?

What should I pass a a string imput?

a new name? with or witout extention? I tried both and couldn't get it to work.

a new path as a string? it didn't work either..

Please help


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 1 of 10
(10,940 Views)

What happens if you get the VI Reference property from the project item and then call the Save method on that?


___________________
Try to take over the world!
Message 2 of 10
(7,431 Views)

It works, the VI is renamed and in the project, the new VI replaces the old one (the old one is removed from the project)!


Thanks for the idea!

here's my VI :

Rename Project Item VI_BD.png


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 3 of 10
(7,431 Views)

This code is awesome!  I have replicated it in LabVIEW 2009 but with one problem.  When I rename the VIs, the callers are not saved, and so all of my old VI names go into the Dependencies folder.  My invoke node for saving does not turn blue, however, and is only called Save.Instrument.  I'm guessing that the "and Callers Debug" part is what saves all the references?  Is there anyway to do this in LabVIEW 2009?  Thanks!

0 Kudos
Message 4 of 10
(7,431 Views)

The node would not turn blue, because the standard save method is not private. I don't know if the method Antoine used is available in 2009, but even if not, you can easily use the VI's Caller's property to get the name of all the VIs that call it (that are currently in memory in the current project) and then call the save method on each of them after saving the VI.


___________________
Try to take over the world!
Message 5 of 10
(7,431 Views)

I've tried several ways to implement your suggestion, but am having difficulty with the concept of VIs loaded in memory.  It would seem that unless I have a reference to the callers already open in my script, the "Callers" property returns nothing, even though I have the project open while I am running my script.  So when does LabVIEW load VIs in memory?

0 Kudos
Message 6 of 10
(7,431 Views)

Generally, a VI is loaded when you open it or a VI which calls it. Additionally, classes load their members when you open a project they're in. That means that you need to open the top level VI (opening a reference to it should work as well). I'm guessing that the project classes do have a property or method for finding all the items with no callers, but I'll leave to you to search for it.


___________________
Try to take over the world!
0 Kudos
Message 7 of 10
(7,431 Views)

I can't figure out how to rename Virtual Folders. You said you used the rename method. Where is it?

0 Kudos
Message 8 of 10
(6,536 Views)

I have just spent an hour browsing and testing the properties and methods of project items and target items and what not - everything that sounds promising to be able to change the name of a virtual folder is read-only. It is kind of irritating that a Type String "Folder" exists while it seems impossible to cast a ProjectItem Reference into this very type of reference. There simply seems to be no such thing as a reference of type "Folder" inheriting from class "ProjectItem"...

0 Kudos
Message 9 of 10
(6,527 Views)

The only way I found to do it was to create a new Virtual Folder with the new name using Add Item, then remove each item from the old folder using delete, then add them to the new folder with Add Item, then delete the old folder. This had to be done recursively when there are sub folders as well.

0 Kudos
Message 10 of 10
(6,512 Views)