VI Snippets are a new way to store, share and reuse small portions of LabVIEW code. VI Snippets combine the portability of a screenshot with the functionality of a VI file by embedding LabVIEW code in a standard PNG image. When you drag a VI Snippet PNG image onto the block diagram it will drop the snippet as graphical code that can be edited and used in your application.
Traditionally, you could share LabVIEW code in one of two ways; as a .VI file, or as a screenshot of the block diagram. A VI contains functional, reusable code, but you must have LabVIEW installed to see the block diagram. Screenshots are easily embedded in documents, forum posts and emails, but they require that you recreate the code from the image, which may contain items like case structures that obscure some of the diagram from view.
To create a VI Snippet, select a portion (or all) of your block diagram and select Edit»Create VI Snippet from Selection. Then choose where you would like to save your VI Snippet.
The PNG file you save is a screenshot of your selected code with LabVIEW code embedded within. All VI Snippets have a border and icon to indicate that you can drag them into LabVIEW to add the code to your Block Diagram.
Figure 1 - The frame with the dotted line lets you know that the image is a VI SnippetNote: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
You can now share your VI Snippet online anywhere images are allowed including blogs, NI Discussion Forums, and the NI User Community.
To add a VI Snippet to your block diagram, drag the image from file manager (such as Windows Explorer) or Internet Explorer onto a Block Diagram Window.
Figure 2 - VI Snippets make sharing code on the community easy
Generally dragging and dropping an image file onto your block diagram will add an image decoration to your block diagram. VI Snippets are special PNG images that have LabVIEW code in addition to the regular image data. When you drop a VI Snippet onto the block diagram you get the depicted code added to your VI.
One time saving tip is to create a folder to save VI Snippets in locally. Whenever you come across a piece of code you find yourself recreating many times save it as a reusable VI Snippet. You can create VI Snippets from portions of code that would have broken run arrows or empty structures that would not work well as SubVIs.As VI Snippets contain VI information they retain anything on the block diagram such as comments, decorations, and data stored in constants.
If you are asking for help on the support forums, use a VI Snippet to post just the section of code you are working on. This way everyone visiting the forums can see your code and potentially weigh in with suggestions without having to download and open your VI. If you are answering someone else’s question a Snippet is both visible and useable – making it easier for many people to learn from your example.
You can create VI Snippets that reference SubVIs but your end users need to have the SubVIs on their machines to be able to use the code. VI Snippets only contain information from the block diagram you create them from. If your code segment contains a SubVI, the SubVI is not embedded in the VI Snippet.
Firefox and other browsers behave differently to Internet Explorer in the way they handle dragged images. When an image is dragged from Internet Explorer, it is on the clipboard, which allows LabVIEW to easily convert the image metadata into code. Alternatively, if you drag from Firefox or Chrome directly to LabVIEW you will get the URL of the image rather than the code you expected.An easy way to get around this is to drag the image to your desktop or a folder first, and then drag the image from your desktop to LabVIEW.
Keeping a local copy of useful VI Snippets will also make it easy to find them again in the future.
Image editing programs that do not understand the extra data embedded in the VI Snippet will remove the VI information if you edit the PNG file. This will prevent the code from dropping in LabVIEW. To avoid this happening, refrain from editing VI Snippets outside of LabVIEW. If you want to add comments or annotations, add them to your block diagram before creating the VI Snippet.
Here are some examples of potential time-savers.
Figure 3 - Structures pre-populated with common code segmentsNote: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
Figure 4 - Templates for common types of VIs (note the black "undefined" wire)
Figure 5 - Code that commonly goes together
Figure 6 - Preconfigured VI calls with input values already wired
Figure 7 - Common data sets such as sample input data used during debugging
Figure 8 - Customize comments once and quickly add to multiple VIs
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.