05-03-2010 03:00 AM
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
05-03-2010 04:21 AM
What happens if you get the VI Reference property from the project item and then call the Save method on that?
05-03-2010 05:19 AM
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 :
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
11-08-2010 01:49 PM
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!
11-14-2010 11:40 AM
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.
11-15-2010 09:09 AM
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?
11-15-2010 12:15 PM
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.
03-31-2018 12:29 AM
I can't figure out how to rename Virtual Folders. You said you used the rename method. Where is it?
03-31-2018 04:48 AM
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"...
04-04-2018 10:13 AM
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.