LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Taggart

Allow a general purpose "on Save" hook

Status: New

This is related to this issue, https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Run-Code-Cleanup-profile-Nattify-VI-on-Save/idi-p/429...

and is a more general request.

 

Have the ability to run custom scripting code on a save event.

 

What problem does it solve?

 

For me personally, I am working on an autoformatter. It would be nice to run that everytime something is saved. Right now I have to monitor the source folder from outside LabVIEW (using Python) and then use G-CLI to run my formatted. I'm sure there are probably other ways to do it and an onSave hook seems like the best choice. 

I'm sure there are plenty of other use cases. Perhaps some kind of linting or enforcing some sort of style guide. ie if you save a VI without a description, it won't let you unless you enter a description. Perhaps even every time you save a file, run some unit tests?

 

Ideal Solution

 

Ideally the scripting code would have access to the reference of the thing being saved. The easiest thing to envision is a VI, but why not also classes, libraries, the project itself? Maybe also some indication of what triggered the save. Was it a saveall, a save all this library, etc. Maybe if it is a saveall, you get a list of all the things being saved, before anything happens?

The IDE would then wait to continue until the scripting code completes, maybe even failing to save on an error or a boolean - not sure if that is the best behaviour as in a bug in your scripting code could cause you not to be able to save - so maybe some way to override the hook?

 

Maybe include a way to autogenerate a VI with the correct connector pane.

 

Maybe it makes sense to generalize this to add more hooks into LabVIEW? Perhaps a call to update the project provider to something more usable/less user-hostile?

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
2 Comments
fefepeto_kb
Member

The idea is good for 99.9% of cases. I think it could be beneficial, but I think some distinction shall be made between text based languages and LabVIEW here:

  • The graphical code might become harder to read if something is not handled properly (something gets hidden, wires become more bendy, etc.). A similar issue might be when the linter cannot apply all the rules, like when a heavily nested structure is already being tabulated close to the line's character limit.
  • Scripting many files when only a type def has been changed that is on the connector pane will become slow and provide a sluggish performance.

For the above reasons, I think something similar to the VI Analyzer automation already possible would be the golden path. If the code got submitted to a branch, then the script would be executed from a pipeline hook. Then resaved an re-committed.

Petru_Tarabuta
Active Participant

+1. I would use the “on save” hook to automatically copy the text found in a VI’s block diagram “main comment” (a block diagram free label whose bottom-left corner is located at co-ordinates 0,0) to the VI’s description. This functionality would be almost as useful and user-friendly as the functionality suggested by this idea: VI Description-linked free label on block diagram and/or front panel.

My current workaround is to use the Free Label To VI Description tool. This however requires the programmer to remember to right-click the “main comment” (which can be any free label, located anywhere on the block diagram) each time the comment is updated. Forgetting to do so results in the VI Description being different than the "main comment".