Automatically Clean Up LabVIEW Block Diagrams
Overview
NI LabVIEW graphical programming is naturally easy for engineers and scientists to understand because of its graphical diagram and dataflow execution. But as LabVIEW applications grow more complex, it can be difficult to maintain well-organized code. For example, consider the last time you viewed the code of a peer or opened a program that you created months ago. You might have been shocked to see a diagram full of disorganized code that would take hours to reorganize using traditional LabVIEW tools such as Clean Up Wire and Align Objects. With the Block Diagram Cleanup tool introduced in LabVIEW 8.6, you can improve the layout of an entire block diagram instantly without manually moving a single wire or object.
Table of Contents
You can use the Block Diagram Cleanup tool to automatically perform the following:
- Rearrange and align every control and indicator on your block diagram
- Reroute and straighten every wire on your block diagram
- Dictate the spacing and compactness of every block diagram object
Figure 1. Rearrange and clean an entire block diagram with a single mouse click.
While the Block Diagram Cleanup tool can make your LabVIEW code much easier to understand, its functionality remains exactly the same after using the tool, just as it does when using Clean Up Wire or Align Objects. There are three ways to perform a diagram cleanup:
- Click the Cleanup Diagram button on the block diagram toolbar
- Select Edit>>Cleanup Diagram from the block diagram menus
- Use the Cleanup Diagram shortcut key by holding <CTRL+U>
Figure 2. Use the Cleanup Diagram button on the block diagram toolbar or <CTRL+U>.
The Block Diagram Cleanup tool has several configurable options that you can access by selecting Tools>>Options and choosing Block Diagram: Cleanup from the category list. Some of the more noteworthy configuration options include the following:
- Horizontal and vertical block spacing – Specifies the minimum spacing in pixels between any two block diagram objects
- Horizontal and vertical wire spacing – Specifies the minimum spacing in pixels between any two wires or any wire and any block diagram object.
- Fix controls to left of the containing diagram – Moves all controls to the left side of the block diagram. If a control is inside a structure, LabVIEW moves the control near the left border of that structure.
- Fix indicators to right of the containing diagram – Moves all indicators to the right side of the block diagram. If an indicator is inside a structure, LabVIEW moves the indicator near the right border of that structure.
- Layout quality – Determines how much time LabVIEW spends cleaning up the block diagram. A higher layout quality results in a more compact block diagram.

Figure 3. Customize cleanup settings including wire spacing, block spacing, and layout quality.
It is important to note that the Block Diagram Cleanup tool cannot perfect the layout of your block diagram. Each user has unique preferences for object spacing, alignment, and density. The Block Diagram Cleanup tool significantly improves the appearance of your code, but it is most powerful when you use it with the other tools such as Align Objects. For example, you can begin by selecting Cleanup Diagram and then using the Distribute Objects tool to make additional spacing adjustments.
Figure 4. Diagram Cleanup is most powerful when used with tools such as Align Objects.
The top five tips for using the Block Diagram Cleanup tool are the following:
- Always save a backup copy of VIs that you will be applying the Block Diagram Cleanup tool to for the first time. You can also “Undo” (Edit>>Undo Cleanup or <CTRL+Z>) a cleanup as long as you have not saved the VI since performing the Cleanup Diagram.
- Choosing to “Fix controls to the left of the containing diagram” in the options menu means all controls. Take time to assess your block diagram before selecting this option to ensure this is your desired outcome. The same should be noted for the “Fix indicators to the right of the containing diagram” option.
- With the Block Diagram Cleanup tool, you can make better use of the [TBD link to Quick Drop DevZone|Quick Drop] feature, introduced in LabVIEW 8.6. By combining the predictive text of Quick Drop with the Clean Diagram shortcut key, you can program code quickly and cleanly.
- LabVIEW considers object labels as part of a block diagram object. This means labels for objects such as controls and indicators are moved with their associated objects.
- The Block Diagram Cleanup tool does not move free labels, such as text and comments added to your block diagram. Keep free label positions relatively intact by nesting them within a structure such as a while loop.
You can use the Block Diagram Cleanup tool to rearrange an entire block diagram in seconds with a single mouse click. Though the Block Diagram Cleanup tool is not intended to perfect the layout of your block diagram, configuration options do give you the ability to specify wire spacing, block spacing, and diagram compactness at the pixel level. When used with functionality like Align Objects and Quick Drop, the Block Diagram Cleanup tool becomes a powerful tool for developing clean code quickly.
- To learn more about new LabVIEW 8.6 features, visit the LabVIEW 8.6 portal
- To try new features now, Download LabVIEW or launch LabVIEW online
- LabVIEW Help: Block Diagram Cleanup
- LabVIEW 8.6 Upgrade Notes
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
