Automatically Clean Up LabVIEW Block Diagrams

Publish Date: Jul 31, 2009 | 25 Ratings | 4.00 out of 5 | Print | 2 Customer Reviews | Submit your review

Overview

Well written NI LabVIEW applications have block diagrams that are organized and easy for other programmers to read. The Block Diagram Cleanup utility was introduced in LabVIEW 8.6 to help you automate the task of organizing code, and additional functionality to help preseve label locaitons and select the portion of code to be cleaned was introduced in LabVIEW 2009.

Table of Contents

  1. Overview
  2. How the Block Diagram Cleanup Tool Works
  3. Enhancements in LabVIEW 2009
  4. Tips and Tricks for Using the Block Diagram Cleanup Tool
  5. Develop Clean Code Quickly with the Block Diagram Cleanup Tool 
  6. Next Steps 
  7. Related Resources

1. Overview

You can use the Block Diagram Cleanup tool in NI LabVIEW software to:

  • Rearrange and align controls and indicators on your block diagram
  • Reroute and straighten wires on your block diagram
  • Cleanup a selected portion of your block diagram
  • Exclude a section of your code from any cleanup operations

Figure 1. Rearrange and clean your block diagram with a single mouse click.

Back to Top

2. How the Block Diagram Cleanup Tool Works

The Block Diagram Cleanup tool organizes your LabVIEW code to make it easier to understand, but the functionality of your application 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:

  1. Click the Cleanup Diagram button on the block diagram toolbar
  2. Select Edit»Cleanup Diagram from the block diagram menus
  3. 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 can be configured by selecting Tools»Options and choosing Block Diagram: Cleanup from the category list. For more information about each option, consult the LabVIEW Help.

Figure 3. Customize cleanup settings including wire spacing, block spacing, and layout quality.

Back to Top

3. Enhancements in LabVIEW 2009

Inspired by feedback from the LabVIEW user community, NI added two significant capabilities to the Block Diagram Cleanup tool in LabVIEW 2009.

1. Clean Up Only What You Want
Cleaning up a block diagram in LabVIEW 8.6 was an all-or-nothing operation. With LabVIEW 2009, you can choose which elements of your diagram you want to clean up. Simply select a portion of code and click the toolbar icon to clean up just that area.

2. Protect Already Clean Code
If you have a particular structure such as a while loop or case structure that is already organized, you can prevent the Block Diagram Cleanup tool from making any changes to your already clean code by right-clicking on the structure and selecting “Exclude from Diagram Cleanup.”

Back to Top

4. Tips and Tricks for Using the Block Diagram Cleanup Tool

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 other tools such as Align Objects. For example, you can begin by selecting Cleanup Diagram and then use the Distribute Objects tool to make additional spacing adjustments.

Figure 4. The Block Diagram Cleanup tool is most powerful when used with tools such as Align Objects.

Follow these tips to use the Block Diagram Cleanup tool successfully:

  1. Always save a backup copy of the VIs you are cleaning for the first time with the Block Diagram Cleanup tool. You can also “Undo” (Edit»Undo Cleanup or <CTRL-Z>) a cleanup as long as you have not saved the VI since implementing the Cleanup Diagram function.
  2. 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 is true for the “Fix indicators to the right of the containing diagram” option.
  3. 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.
  4. 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.
  5. Once you are happy with the layout of a certain structure such as a while loop, you can right-click on the loop and select “Exclude from Diagram Cleanup” to prevent further modifications.

Back to Top

5. Develop Clean Code Quickly with the Block Diagram Cleanup Tool 

You can use the Block Diagram Cleanup tool to rearrange just one area of your code or 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.  

Back to Top

6. Next Steps 

Back to Top

7. Related Resources

 

Back to Top

Customer Reviews
2 Reviews | Submit your review

 - Nov 18, 2009

All this stuff and no Zoom function. Why can't we have a zoom function?

 - Aug 11, 2009

This is BY FAR the most powerful improvement. Saving me up to 30-50% of my development time, cleanup is hugely important. This update with the exclusion flag is better than I wished for.

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit