LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/18/2009) - Code Snippets

I agree with the copy/paste issues, but I think the method is simple and effective and avoids the reference issue.  The snippets/fragments are completely interchangable, and if you like you can use snippets when they work and fragments when they mess up.   I have tossed around some ideas to add controls, fix up wires, etc., but decided it isn't worth the trouble (especially since my scripting experience consists of about an hour of experimentation).  A slick UI (ie. keyboard shortcut) would make it very elegant.  As soon as I learn to search for all objects of a given type inside a selection, I'll probably add a warning message when certain structures are included (broken wires, implicit references).  Fixing (automatically) is hard, but identifying seems tractable.

 

All that has stopped me at LV8.6 is the availability of scripting (at least public availability).  

 

I am working to add a 'Save for previous' option to the snippets I create in LV9 to make them automatically compatible with 8.6 (or earlier).  I am still trying to decide on the feasibility of having multiple versions in a single fragment. Size limits of forum post images is the biggest consideration right now.  As long as we remember the primary purpose of sharing/reusing small pieces of code, there shouldn't be a problem.  My rule of thumb is that if the image is too large, you are probably trying to include too much code.  (Large empty structures being a noticable exception).

 

Adding to the CCT would be great, the addition of a legitimate UI would be more than welcome.  If the caveats are clearly documented, then I believe we will have an effective tool.  If it stirs up enough interest, perhaps we'll get the inside help we need to make snippets work the way we would like.  Operative word being work.

0 Kudos
Message 31 of 34
(1,365 Views)

The very good news is I was able to create a snippet with the CCT in LabVIEW 7.0 that I could drop into LabVIEW 2009:

 

CCT_Generate Help Image_BD.png

 

One of the options I was thinking about is a customizable header.

This header is:

$VERSION$ $DATE:%c$

 

$VERSION$ is replaced with the current LabVIEW version

$DATE:xxx$ is replaced by a timestamp with xxx as the timestamp formatter.

 

So you can add your own message.

 

Any more ideas?

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 32 of 34
(1,357 Views)

For the LV8.6 users out there, here is a version for you.  Use the 'Make Fragment' VI to make the fragment file.  Run 'Fragment Helper' to go from the PNG file to LV code.  In AutoHide mode, the window stays minimized in the task bar when an operation is complete.  You can drag a file to the title bar in the task bar and the VI will Restore so you can drop the file in the path control.  The rest is taken care of.  You can select a New VI or the clipboard as the destination for the code.  Once in the clipboard you can paste at will.  No drag from web page yet, feel free to try to add that feature.

 

Not a lot of testing, so plenty of bugs for sure, but you can play around with code fragments.   Probably could use a little more error checking, I check for a png extension, but not for code inside the file yet.  Enjoy.

 

 

Message 33 of 34
(1,349 Views)

Darin -- I haven't had a chance to look at your MakeFragment code but I can contribute some code I think you guys (and girls) might find useful.

 

I've attached two zip files, both of which should be unzipped to your quick drop shortcuts folder <National Instruments>\LabVIEW 2009\resource\dialog\QuickDrop\plugins\

 

Once you have done this you will have two new quick drop shortcuts:

 

 

  • Press Ctrl-space, then Ctrl-U to convert a comment containing a path to a snippet into the code contained within that snippet.  This is incredibly useful for people (like myself) who use Google Chrome or Firefox as their daily browser.  Drag a snippet from Firefox, press Ctrl-space, Ctrl-U and voila!  No need to drag to desktop.
  • Select some code and press Ctrl-space, then Ctrl-Y and the plugin will create a snippet of the code and by default save it to a temporary location and put the path to the temp file on the clipboard (similar to the CCT behavior).  A dialog will popup with additional options but pressing return will just give you the defaults.  All the underlying code is unlocked LabVIEW code (using scripting) so the snippet behavior is not identical to the underlying method used by LabVIEW (implicit references and broken wires are copied "as-is").  Whether or not you find the plugin useful you (or Ton) may find the underlying code helpful.  This code will also allow you to create snippets from front panel objects (the snippet still needs to be dragged to the block diagram though).

 

 

This is not official "NI" code -- just some VIs I wrote for my own personal use which I figured wouldn't hurt to share.  As such the code is truly open source i.e. not supported, not guaranteed fit-for-function, but you are free to modify it.  This code also hasn't been through much testing (I'm a product manager, not a developer - what time I can spend programming is generally not spent testing).  Please keep the spirit of VI Snippet in mind as you are modifying the code -- namely a way for us to freely share LabVIEW code and ideas over the web.

 

Simon Hogg

LabVIEW Product Manager

 

Download All
Message 34 of 34
(1,237 Views)