• Malleable VI banner

Make efficient reuse with Malleable VI

posted in: NI LabVIEW | 0

I’m pretty sure most of us are good at developing reusable VIs in LabVIEW and using it. One pain point that developers face is – how to manage the VI’s that have same functionality and different in datatype.


Let’s say we want to develop reusables for ‘Calculating Array Differences‘ for the double and I32 array. Then we would develop 2 VI’s as shown below,

Code snippet of the reusable VIs with different data types
Code for Calculate Array Difference of 1D double and I32 element


Developing reusables is the first part but how to organize and let the user access them easily is also important. One option is to use polymorphic VI’s. Developers can build a polymorphic VI and group VI’s in them as shown below,

Polymorphic VI window that shows the all the VIs with only difference in datatypes
Array Difference Polymorphic VI


This doesn’t solve the problem but only organizes the problem. Maintaining several VI’s is only going to make things worse. What if we could create one VI that adapts its behavior based on the datatype (something similar to LabVIEW native add function)? No, I’m not talking about the GenericAreGo = True


Malleable VI to the rescue

Malleable VI is a new VI type with .vim extension, its terminals can adapt to its input data type when called from a calling VI. As Malleable VIs are always inline, when dropped into the calling VI and connected to an input datatype, LabVIEW could perform a type propagation and confirm the data type adaption. This is what NI had to say.


If we can translate the Malleable VI to the previous example, We need to create one malleable VI and that’s it!

Malleable VI code snippet for calculating array difference
Array Difference Malleable VI


When called ‘Calculate Array Malleable VI’ will adapt to the input data type. In the below VI notice that there is no coercion dot

Calling Malleable VI code snippet for calculating array difference
Calling Malleable VI

But if the Malleable VI doesn’t support a certain data type, then LabVIEW type propagation will identify it and makes a broken wire in the calling VI. In our example, connecting string datatype will not work as ‘subtract’ function doesn’t support string data type

Broken when calling Malleable VI code
Broken when calling Malleable VI


The challenge here is logic\code cannot be data type independent always. What if we can make the Malleable VI to intelligently choose the one of many logic based on the input data type? NI LabVIEW have a solution for this!


Welcome to the Magic Case structure!

Most people call this ‘Type Specialization Structure’ – In each case of this structure user can write a logic assuming the input data type. During type propagation, LabVIEW will choose a case that doesn’t break. For example, if we need to make the malleable VI support ‘Calculate Array Difference’ for a string datatype do the below,

Code snippet for supporting string datatype using Type Specialisation Structure
Supporting string datatype using Type Specialisation Structure


In the above image, we have two cases,  one supports the numeric datatype (left) and another supports string datatype (right). In the right image, ‘string to decimal number’ function breaks the wire as the input is number now but when a string datatype is inputted to this VI, right image will not break (left side case will now break).

Code snippet for calling the type specialization VI
Calling VI supports both numeric and string


Now we can develop a single VI with many logic for different data types. Isn’t that powerful? Best luck with this.


Things to remember

  • Malleable VI are always inline
  • Inline VI doesn’t support few property nodes and so some of the property nodes cannot be used in a Malleable VI
  • Type Specialization structure is not complete – Be careful!
Boring Engineer
Follow Boring Engineer:

Industrialist and CEO of Stark Industries, once a Patriotic Winter Soldier, After an Accidental Gamma Ray exposure became a strange magician. Talented at archery and swinging between buildings. Popularly called as Son of Odin or King of Wakanda!

Boring Engineer
Latest posts from

Leave a Reply

Your email address will not be published. Required fields are marked *