LabVIEW Craft
  • Blog
  • About
  • Contact
  • Tools
  • Resources

Merry Script-mas!

12/19/2016

3 Comments

 
Ethan Stern
Every time I hear someone claim that the NI Actor Framework is hard to use or that it "slows down the IDE", a little part of me dies inside. Advanced actor-oriented design isn't simple, you say? I wholeheartedly agree. ...But, since when did expertise with a hammer--or, let's say, the producer-consumer design pattern--suddenly make someone Frank Lloyd Wright?
Picture
If it's not blatantly obvious, I value the Actor Framework (AF) as an important part of my toolkit. It's not the right tool for every job, but it is a useful tool for many. One part of the AF I don't love is the necessary tedium of building Actor Core event-handling UIs and then dragging reference controls (for my by-reference updates) into the Class Private Data Cluster. This got me thinking... In general, adding controls to a class feels like a relatively clumsy process, even when not using the AF. I let this mild frustration stew inside my melon for years, and then I finally did something about it.
Picture
A good ol' fashioned event-handling Actor Core. (Notice the bundling at left.)

The Gift That Keeps On Giving

As a reader of LabVIEWCraftsmen.com, you're already using Quick Drop (Ctrl+Space), so I won't waste our time describing that. However, if you don't already know the joys of VI Scripting, please allow me to rock your world.

I hope you already know that there's a fast and easy way to remove (Ctrl+R), replace (Ctrl+P), insert (Ctrl+I), and automatically wire (Ctrl+W) VIs and nodes. If this is news to you, please immediately try this experiment:
​
  • Open a VI
  • Quick-Drop Open/Create/Replace File
  • Quick-Drop Read Text from File
  • Quick-Drop Close File​
​You should have this:
Picture
  • Highlight all of them (Ctrl+A, or just use the mouse)
  • Launch Quick Drop ONE MORE TIME
  • With the Quick Drop window open, press Ctrl+W
Now you have this:
Picture
Voila! You just replaced eight (count 'em) manual, and precision-demanding mouse clicks with one control-key press. This is the magic of VI scripting and--the best part is--you can write your own custom scripts to automate your most tedious editing operations.
To install a new LabVIEW script (like the one below) on your computer, simply place the scripting code in one of two locations:
  • [LabVIEW]\resource\dialog\QuickDrop\plugins
  • [LabVIEW Data]\Quick Drop Plugins
To confirm the script was loaded by LabVIEW, or to assign a new default Ctrl+Key shortcut to a script, launch Quick Drop and press the "Configure..." button in the bottom-right corner.
Picture

My New Toy: Add To Private Data

I use at least some classes in nearly all of my LabVIEW development. While class data are encapsulated (private) for a purpose, I see no reason that defining and editing class data in the IDE need be a slow or tedious process. After thinking about how I wanted this to work, I wrote a script to automate the annoying part:

(scripted actions in green)
  • Create a class
  • Write some methods
  • Decide certain values or reference controls need to be in the class Private Data Cluster
  • Add the data (value controls) or add references to controls (reference controls) to the Private Data Cluster with a Quick Drop Ctrl+key shortcut​
...And, when I'm adding reference controls from an Actor Core.vi, also do this:
  • Insert a Bundle By Name node onto the Actor wire (or expand the existing node)
  • Move all Control Reference Constant labels to the left side (so they don't overlap)
  • Wire the Control Reference Constants into the Actor Core bundle node
  • Tidy up by aligning the new Control Reference Constants with their bundle terminals
Here's how it works from an ordinary (non-Actor) method:
  • From the front panel or block diagram, highlight the controls,  indicators or constants you want to add to the Private Data Cluster.
Picture
  • Launch Quick Drop with Ctrl+Space
  • Press Ctrl+O to add the items to class data as data values; OR
  • Press Ctrl+Shift+O to add the items to class data as Reference Controls

Depending on the state of your Shift key, the result will be one of these:
Ctrl+O
Ctrl+Shift+O
Actor methods have the same funtionality (they are just member VIs, after all) with the exception of that very special method called Actor Core.vi:
  • Use the same workflow as above, but notice that Ctrl+Shift+O magically (I hope) bundles the scripted Control Reference Constants onto the Actor's data wire.
Highlight the items to add (Diagram or Panel)
Ctrl+Shift+O

Wrapping Up

Here are a few additional notes on this script as it stands right now:
  1. I wrote this script in LabVIEW 2015.
  2. Scripts must make assumptions, and those assumptions I programmed into this script work well for my development process (I don't know yours, but let's talk!)
  3. This script is a work in progress, especially the Actor Core bundling. ("If you're not embarrassed by the first version...")
  4. If the selection list contains a mixture of GObjects with different by-ref/by-value assumptions (on my part), they all get added to class data, but in a way that makes sense individually.
  5. Constants are always added to class data as value controls (not reference controls) because that was the only action that made sense to me.
  6. Tab Controls are always added to class data as reference controls because the alternative value control is almost certainly not what I want (and easy enough to place manually if I really do want it).
  7. If you or someone you know has already written/shared/published a similar script, please let me know, because I think we need to be friends.
Last, but not least, please share your thoughts and ideas for making this script better! I'm happy to refine it and make it more robust--but I'm also happy if you do.

​You can download the Add to Private Data script (and others) from our public Bitbucket repo.
3 Comments
Jens Christian Østergaard Andersen
1/3/2017 01:53:08 pm

Hi Ethan.
Nice work with the scripting, I really like that :-)

From what I read here it seems that you always update you UI elements by passing there references to the methods that generate / manipulates data for them. I have not worked that much with the AF myself, but I prefer to update my UI elements by generating user events for the Actor Core event structure. This is because I do not like to pass the bare control refs around and the fact that all VI’s that operate on the controls refs will be forced to switch to the UI thread. What is your take on that?

Reply
kosist link
3/16/2018 04:55:41 pm

It'll be handy to put references into typedef cluster, and then that typedef cluster put to Actor's private data. Then control references will be grouped inside class data in the cluster, so will be easier to manipulate with references at the end, from one cluster node...

Reply
Donut Recipes link
5/6/2023 02:12:06 am

Good readding your post

Reply



Leave a Reply.

    RSS Feed

    Tags

    All
    Abstract Messaging
    Actor Framework
    Agile
    AI
    Asynchronous Programming
    Best Practices
    C#
    Complexity
    Continuations
    Control Values By Index
    Craftsmanship
    Dependency Inversion
    Dependency Viewer
    Futures/Promises
    Genetic Algorithm
    Liskov Substitution
    Malleable VIs
    Mediator Pattern
    .NET
    Object Oriented
    Object-Oriented
    Packed Project Library
    Parallelism
    Polymorphism
    Pub/Sub
    RawCap
    Root Loop
    Scrum
    Task Parallel Library
    TCP/IP
    TDD
    Test Engineering
    UML
    Unit Test
    VI Scripting
    VI Server
    WireShark

    Archives

    October 2019
    April 2019
    July 2018
    October 2017
    March 2017
    February 2017
    January 2017
    December 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    August 2015
    February 2015
    January 2015

    LabVIEW Blogs

    Eyes on VIs
    LabVIEW Hacker
    VI Shots
    LabVIEW Artisan
    Software Engineering for LabVIEW
    ​Wiresmith Techology
Picture
Powered by the Panda Ant

  • Blog
  • About
  • Contact
  • Tools
  • Resources