As Quick as a Quick Drop

One day, I realized there are some operations in LabVIEW I use dozens of times a day. The sequences may be short (5-10 actions), but that doesn't make them any less boring. As a developer, when you have to write the same code again and again, you create a function/subVI. But what can you do when the repetitions are not a piece of code, but a series of manual operations? Same answer: create a subVI! Err, sure thing, but how do I do this?

The answer can be found in LabVIEW 2009 (or LV 8.6 through NI Labs) and later versions, and it's called VI Scripting. This particular programmation mode allows you to write pieces of code that create or edit your code in your stead. It's like inventing a recipe, and once you execute this recipe (through a menu or a keyboard shortcut), LabVIEW instantly cooks lasagna for you—if that was a lasagna recipe, that is. In most cases, developers only reproduce other cooks' recipes so they don't have to create their own. After all, a great developer is a lazy developer, amirite?

Quick Drops

There are lots of places in LabVIEW where scripting is used, and some of them allow you to write/use your own scripting code as a plugin. The most famous one is the Quick Drop Keyboard Shortcut, or QDKS, or QD (even though the latter is wrong and tends to irritate Darren Nattinger.) A QDKS is a combination of keys—Ctrl+Space, then Ctrl+<custom key>—which executes some specific VI Scripting code that makes your life easier and helps yous save precious time. Like I said, some developers write QDKS, and make their plugin "recipes" available to a centralized community group. I recommend you to read the first Quick Link on this group before moving forward.

Time for a concrete example! Do you know how many actions it takes to add controls or constants to a new cluster (and make it resizeable)?

Open the functions palette, grab a cluster constant, drop it somewhere on your BD, select the constants you want to insert into the cluster, drag & drop them into the cluster, open the cluster local menu, and select AutoSizing>Arrange Vertically. That's 7 operations!

The following QDKS only requires 2: selecting, then Ctrl+Space,Ctrl+<custom key> (I chose <C>).

Download the Create Cluster QDKS Sample Code

Write your first QDKS

Coming up with a good recipe can be complex—and once again, that's why cooks are here to help— but in case you want to start with something simple, please read on.

With LabVIEW 2012, NI introduced the sample projects, and removed the ability to create a blank project in one click (Project>Create Project...) Nowadays, if the Getting Started Window isn't visible (meaning you actually work ;-)), you have to go though the previous menu, then wait for the dialog box to open, then double-click Blank Project. The dialog box isn't particularly fast as you can see, so the whole thing takes a good 3-5 seconds (and I have a SSD). Let's write a QDKS that creates a blank project and display it!

Start with the QDKS template (the only *.vit file), available here: C:\Program Files (x86)\National Instruments\LabVIEW 20xx\resource\dialog\QuickDrop, and double-click it.

All the comments in the block diagram are relevant, so read them carefully.

Now, make some space, remove anything useless, and write the following code.

Your recipe is now complete. Add some documentation in the VI properties—that helps identifying your QDKS later on—then save the VI, and add it to C:\Users\<username>\Documents\LabVIEW Data\Quick Drop Plugins. Create the folder if it doesn't already exist.

Back to LabVIEW, press Ctrl+Space, and click Configure...>Ctrl-Key Shortcuts. Look for your first QDKS and assign a new shortcut key to it. Like, Ctrl+P is a good fit (New Project QDKS.)

Now let's execute the recipe: open some VI, press the magic shortcut, Ctrl+Space, Ctrl+P, and you shall have a brand new project waiting for your command within the next second.