I have had this in my toolbox for a long time to do what you are asking. It is part of a QuickDrop plugin I made to "fix up" a VI, similar to Darren's Nattify plugin.
Size Diagram Window.vi
The 'Arrange VI Window' Quick Drop keyboard shortcut does this. With the diagram open, Press Ctrl-Space, then once Quick Drop appears, press Ctrl-F.
If you want to look at the code that accomplishes this, see here... it should be a good resource for writing your own tool:
[LabVIEW 20xx]\resource\dialog\QuickDrop\plugins\_Arrange VIWin SubVIs\Arrange VIWin - Arrange BD.vi