Example Code

Get Library Icon (lvlib, lvclass, xnode, xctl) without loading dependencies in memory

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

    Operating System

  • Linux
  • Mac OS X
  • Windows

    Programming Language

  • LabVIEW G

Code and Documents

Attachment

Description

LabVIEW Libraries are missing a key feature to Get Library Icon without loading the library dependencies in memory (Similar to the App : Get VI : Icon invoke node). The current method, using the App : Library : Open > Icon : Get, can take a few seconds to load large libraries or multiple inheritance classes. Since all LabVIEW Libraries (*.lvlib, *.lvclass, *.xnode, *.xctl) use the same XML construct for storing the compressed icon images (XML property tag "NI.Lib.Icon"), we can manipulate the XML DOM to only load the library's icon property tag (and exclude any dependencies).

 

This function dumps the "NI.Lib.Icon" XML Property tag to an empty LabVIEW Library (*.lvlib) XML file then reads the library icon through the default invoke methods. This expedites the load time, removes all dependencies and supports Run-Time System compatibility.

 

 

 

How to Use

Supports all source libraries:
- Library (*.lvlib)
- Class (*.lvclass)
- XNode (*.xnode)
- XControl (*.xctl)

 

Set the Library Path and run the Get Library Icon.vi

 

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

Comments
Novgorod
Member
Member
on

Very cool! It prompted me to do some reverse engineering because the icon information is in the encoded text alone and it seems wasteful to make a temporary library just to use the built-in LV functions. It's not that hard to decrypt it once you get a hang of it - so here it is for posterity:

 

The encoded text in the "NI.Lib.Icon" XML property tag is an XML-escaped linear-alphabet (starting from ASCII 33) base64-encoded flattened variant of a byte array (this is true for any XML property tag with the type "bin"). This byte array is a zip-deflated string with a 4-byte size header indicating the uncompressed (!) string size. The uncompressed string is a pixmap (image data) cluster flattened to string - draw a picture from that pixmap and Bob's your uncle.

XML_icon.png

Gotta be careful how you handle dangling bytes of the base64 decode (when the length is not mod 4) - the unflatten variant function will complain if you get the last bytes wrong (variant padding). Of course you can use any base64 library with a custom alphabet.