Example Code

Programatically Find the Size of Block Diagram In Pixels using LabVIEW

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

Code and Documents

Attachment

Overview
This examples demonstrates how to programmatically find the size of the block diagram in pixels.


Description
For block diagrams and front panels, there is a maximum size limit. More information on this can be found here. Ideally, with good programming practice utilizing concepts such as subVIs, this size limit can be avoided. However, if there is concern about excessive block diagram size, this example provides a way to determine the pixel size.

 

This example uses an Invoke node referenced to the current VI to extract information on block diagram size. Using the Block Diagram’s Get Image Scaled method, we can retrieve Image Data which contains a cluster containing the coordinates of the rectangle bounding the block diagram. The upper left corner of the block diagram is considered (0,0) so the pixel size can be determined with the Right coordinate and Bottom coordinate. In other words, the size of the block diagram would be <Right Coordinate> pixels by <Bottom Coordinate> pixels. 

 
Requirements

  • LabVIEW Base Development System 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Create an invoke node. Right click it and select Class » VI Server » VI » VI.
  2. Click the invoke node and select Block Diagram »  Get Image Scaled.
  3. Wire an Unbundle by Name function to the Image Data output.
  4. Click the Unbundle by Name function and select Rectangle » All Elements.
  5. Create an indicator to see the data. This gives you the coordinates of the bounding rectangle of the block diagram, where the upper left corner is (0, 0).

 

Additional Information or References

VI Block Diagram

block.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Tori
Student

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