Rename AF Message
I inherited a project written using Actor Framework recently. I started to do a little refactoring to make it easier to add some of the changes I needed to make, following Kent Beck’s idea of “First make the change easy, then make the easy change.”
What is in a name?
They say naming is hard and it is. In this case, the names of the messages didn’t quite reflect my understanding of what they did. So I wanted to change the names of these messages, to make things just a little easier to understand.
How hard can it be?
Well, the first question you might have is: “How hard can it be to rename a message?” The answer is surprisingly difficult. One may argue that the AF does some things well, but one of those is certainly not allowing for refactoring. When you say “rename a message”, it sounds like one atomic action. The reality is quite different.
The name of a message in AF actually shows up in several places.
- The name of method on the Actor, which is called by the Message Class Do VI
- The name of the Message Class itself
- The folder the Message Class is in
- The name of the Send VI
- The label of the class controls in the Do VI
This is of course assuming that one originally created the message using the normal AF message scripting tools that ship with LabVIEW.
For consistency’s sake and to be kind to your future self, you really want to change all of those references at the same time. That’s a lot of clicks and a lot of things to remember. It’s prone to human error. Changing a single message by hand is doable, but in my case, I wanted to change a bunch of messages. I thought there must already be some tool to do this, but I couldn’t find one. Admittedly I didn’t look too hard. I immediately jumped to “I can probably create a tool for that myself.” So I did.
Rename AF Message
I wrote a very simple tool that runs from the Tools Menu. You point it at a Message Class and give it a new name. It takes care of the rest. It renames the message class and moves everything into a renamed folder. It cleans up the names of the class controls and indicators. It renames the send VI and optionally renames the Actor method associated with the message.
So instead of remembering a bunch of steps and executing dozens of clicks, it’s reduced down to 4 actions.
- Launch the tool
- Select the Message Class to Rename
- Provide the New Name
- Click OK
Limitations
Works on direct messages, not abstract messages. Not tested with interfaces (yet), but in theory, I think it should work. It assumes that the message was created by the AF Message Maker Tool and that you didn’t go around messing with the message afterward, liking renaming things or moving them around on disk.
The code does need some cleaning up. At first, I just wrote the most rudimentary scripting just to do a proof of concept and knock out what I needed for this project. The idea of distributing it came a little later. I’ve started to clean it up a little, but it could definitely use a little refactoring.
Written in LV2020, although it is open source and doesn’t use anything 2020 specific, so you could totally clone the repo and back save it.
Future Improvements
I’m probably going to upgrade the GUI in the future so that instead of selecting the Message Class by path, you’ll get some sort of dropdown or listbox listing all the message classes in the project. It could also use a little polishing in terms of aesthetics. It might also be good to remember the Selection for updating the Actor Name from one call to the next.
Try it out
Get the latest release here:
https://gitlab.com/sas-class-refactoring/rename-af-message/-/releases
Help
If you need help untangling legacy AF projects, we can help. Use the button below to schedule a call.