LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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


Darin.K wrote:
Thanks for the image, very suggestive.  If Rolf is working on it I am sure it is done well.  Do you have the link to that thread, I have missed it.  I would like to see how he handles the dropping of the BD aspect.  My current method is a little clumsy and involves running a helper VI.  My primary motivation in adding an 8.6 version is that I can embed multiple versions in a single snippet and the proper one can be extracted based on LV version.  This way, when I use snippets to post a short example it isn't limited to people with LV 9.  It all works for me at this point, but the user interface for 8.6 is a stumbling block.

 


Yes this was a proof of concept for myself. I have created fully working code to create the VI snippet with the VI involved, and yes there is a complete VI in that snippet as in any other VI snippet. What I do, and NI most likely too is using the private (or is it LabVIEW API?) method to create a subVI from selection, turn that into a string instead of saving it to disk (a private Save method for a VI) and store that VI as an extra chunk into the png file. And this methods should apparantly work back to 8.5 even.

 

I have meant to work on some code that does the create SubVI stuff the hard way using LabVIEW API methods that work back to 7.1. While I have an idea and some proof of concept, that whole thing is rather cranky, ugly and still not fully working

 

The other part of merging the code by drag and drop is however a bit more complicated. First of all there is no easy way to drop into a LabVIEW diagram without some external code and hooking into the LabVIEW windows message handler. This is however very ugly, and absolutely not plattform independant. So what I have been thinking about is to use a small helper floater VI with a string control which since at least LabVIEW 7.1 also supports dropping into and in the case of an image from at least Firefox it shows the actual URL of that image, and then download that file using some HTTP VI's. And then oh well, how to let the user decide in what diagram he wants to drop it????

 

Rolf Kalbermatter

 

Rolf Kalbermatter
My Blog
Message 21 of 34
(1,818 Views)

Matthew Kelton wrote:

 

It does not appear to work natively by dropping it into LV 8.6.1


No it can't. This was most probably sort of a late idea added to LabVIEW 9.0 just before the code freeze. There is unfortunatly no way to hook easily into any diagram to support native drag and drop support as this is something that needs to be added deep down in the belly of LabVIEW OS window message handling.

 

The only way to support something similar in earlier versions is by providing some helper VI that acts as drop target and receives the VI snippet, and instantiates it as a VI and then opens it so the user can look at it. How to easily allow a user to integrate the diagram from there into his own VIs I have not really thought about yet.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 22 of 34
(1,816 Views)

My current implementation is very similar (posting soon I hope).  I hook into the Copy/Paste methods to generate the VI which I stuff into a PNG file.  The task was made much simpler since LV9 treats the VI as a shell VI so it drops the BD code instead of just the subVI.  In LV8.6 I have a crude helper which acts as a drop target, extracts the VI and copies the BD to the Clipboard to be pasted at will.  As Rolf alludes to, no direct web->BD drag, it has to be saved to file first, much like the method for unsupported browsers in LV9.

 

0 Kudos
Message 23 of 34
(1,799 Views)

Darin.K wrote:

My current implementation is very similar (posting soon I hope).  I hook into the Copy/Paste methods to generate the VI which I stuff into a PNG file.  The task was made much simpler since LV9 treats the VI as a shell VI so it drops the BD code instead of just the subVI.  In LV8.6 I have a crude helper which acts as a drop target, extracts the VI and copies the BD to the Clipboard to be pasted at will.  As Rolf alludes to, no direct web->BD drag, it has to be saved to file first, much like the method for unsupported browsers in LV9.

 


Actually there is not really a need to save the file to disk. Just as there is a private Save to Strinh Buffer method to get the VI directly into a memory stream, there is also the opposite (which I think to remember is a private application method). But this is just cosmetics. There is little difference in practice if you save the file to disk first or instantiate it directly into memory.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
Message 24 of 34
(1,798 Views)

I am stuck in the confines of the public propeties and methods, but I agree that the difference is mostly cosmetic.  As this exercise was mainly for personal edification, and the eventual use of snippets to organize my collection of code fragments, I already have the files on my HD anyway and a little clunkiness is acceptable. 

 

Thanks for the great info, Rolf!

0 Kudos
Message 25 of 34
(1,793 Views)

I'll be happy to look in whatever you have and maybe add some of my own to it, but currently my pet hobby project is to create a fully working HTTPS VI library Smiley Very Happy

 

That is why the VI snippet code actually lingered around once I had proven to myself that I can do it. Smiley Wink

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 26 of 34
(1,792 Views)

Here is the code I use to make 'Code Fragments' in LV9.  It was thrown together during coffee breaks and my daughter's naps so it is still a little rough around the edges.  It requires LV scripting to work.  I highly reccommend scripting, I doubt I will ever generate much code with it, but it does expose some very useful methods.  Of course, like everything else, I wish I could get a little more...

 

To make a Code Fragment simply copy the code you want to the clipboard and run the 'MakeFragment' VI.  You can remove broken wires if you'd like, just remember, what you select is what you get.  Room for improvement on the image.  I have a crude VI which lets me alternatively use a FP image, a control image, or an icon.  Whatever you want, you are in control.

 

So far I really like my property nodes remaining intact, the ability to comment on the fragments, and the ability to organize them using Explorer and dragging to the BD.  Feel free to build on this, if you find it useful let me know.  If you incorporate this into something please give credit where credit is due, ie. a link to this thread or a little acknowledgment to Rolf and/or myself.  

 

I am working on cleaning up the 8.6 version.  Most of the work is done simply converting the enclosed VIs.  A couple extra VIs required to extract the data, and a helper VI to use as a drop zone are being cleaned up.

 

If nothing else, this should be a band-aid for me until NI cleans up the snippet implementation.  My guess is that internally the work is already done.

Message 27 of 34
(1,766 Views)

Hi Darin,

 

With your code I was abel to add a snippet feature to the Code Capture Tool for LabVIEW 9.0 at least. I think the porting to 8.6 won't be too hard.

 

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 28 of 34
(1,701 Views)

Even better news:

 

The methods used (copy and paste selection) are available in LabVIEW 7.0, so very likely this we can create snippets in that version onwards.

 

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 29 of 34
(1,698 Views)

TCPlomp wrote:

Even better news:

 

The methods used (copy and paste selection) are available in LabVIEW 7.0, so very likely this we can create snippets in that version onwards.

 

Ton


Some issues with simple copy and paste do exist in my opinion and that is what made my first attempt get a bit frustrated. If you happen to select some code and some wires with the source or sink of the wire outside of the selection you end up with ugly broken wires. So I was actually going about adding compatible control and indicator controls to the created new VI. And that is were things get a bit difficult.

 

At least for sources it would be beneficial to add the control to the selection before copying it to the clipboard but that modifies the original VI and has to be undone after the copying. Yes it is possible but not exactly neat. Also if you happen to have implicit (not reference wired) property nodes or methods in the selection you should add the according control/indicator also to the selection if it isn't already in there.

 

These two things were where I started to toss around with various ideas how to do this in an elegant way and then the HTTPS/SSL idea struck and the VI snippet got in a backseat position. Smiley Wink

 

Rolf Kalbermatter

Message Edited by rolfk on 09-27-2009 08:10 PM
Rolf Kalbermatter
My Blog
Message 30 of 34
(1,689 Views)