Example Programs

Import VI Snippet (*.png) Programmatically

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

    Programming Language

  • LabVIEW G

Code and Documents

Attachment

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. https://github.com/rcpacini/labview_snippet

Description

Import a VI Snippet (*.png) image programmatically using pure LabVIEW code (No external dlls or dependencies).

 

Pastes this VI Snippet ("..\basic.png"):

Programmatically into an existing or new VI:

 

How to Use

1. Open the "Import VI Snippet.llb:Import VI Snippet Example.vi"

2. Enter the "VI Snippet Path (*.png)"

3. Optional, enter the "Drop Position" in pixels where the code should be positioned on the block diagram

4. Run the VI

The VI Snippet code will import into a new VI.

 

 

Additional Information

VI Snippets are no more than custom PNG data chunks that contain the binary VI file. The library saves and loads the "niVI" chuck to the clipboard (within the context of the block diagram) and then pastes the code to the destination VI specified.

 VI Snippet PNG Chunks:

  • "IHDR": PNG header information
  • "IDAT": PNG image data
  • "niVI": LabVIEW VI code << this is the secret sauce
    • E.g. "RSRC...VI_NAME.vi"
  • "tEXt": LabVIEW VI Snippet help text
    • E.g. "National Instruments Software This image contains an embedded VI File. For more details visit ni.com/info and enter 'ex6a7h' "
  • "IEND": PNG end of file

 

Under the hood, this library does the following:

  1. Read the VI Snippet PNG chunks
  2. Save the "niVI" data chunk to a temporary VI file (*.vi)
  3. Load the temporary VI using VI Server
  4. Copy all Block Diagram content to the clipboard (See below)
  5. Paste the content to the destination block diagram
  6. Delete the temporary VI.

Note: This uses VI Scripting to make a selection of all block diagram objects (i.e. decorations, nodes, sub VIs, wires, etc.) and copys the GObjects to the clipboard in the context of the block diagram. This is a workarround due to the inconsistent nature of the "Place object on cursor" IDE method.

 

Related Links

PNG Specification

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors