jcarmody Posted October 27, 2011 Report Share Posted October 27, 2011 This is a Block Diagram Decoration with a picture of an unshaved Yak. It is a Yak that I very much want to shave... I've posted a question in the NI LabVIEW API Community asking for help: I'm looking for a way to programmatically set the image of a decoration on the Block Diagram. If I have an image on the (Windows) clipboard, I can paste it on a Block Diagram and the Class Name of the object is 'Decoration'. Is there a property or method I can use to set the image of a decoration? Can you help? Thanks, Jim Quote Link to comment
Darren Posted October 27, 2011 Report Share Posted October 27, 2011 Yes, I can help, I have a lot of experience with yak shaving. This video should give you all the information you need. Please follow its instructions carefully, as an unshaven yak is something to be taken very seriously. 1 Quote Link to comment
jcarmody Posted October 27, 2011 Author Report Share Posted October 27, 2011 I can't see Youtube at work, but I'm thinking that you've interpreted my request for help to mean I need help shaving the Yak. I have many years of experience shaving Yaks and can handle it quite well once I have my preliminaries completed. I need help changing the picture in a BD Decoration using scripting. I'll look at the video tonight; It may inspire me. At least you didn't use lmgtfy to answer my question. Quote Link to comment
David_L Posted October 27, 2011 Report Share Posted October 27, 2011 I couldn't find a way to add or replace an image using scripting (however that does not mean it doesn't exist). One thing you could try is deleting the original image and then using the "TopLvlDiag:Paste" Method to paste an image from the clipboard to the block diagram. However you'd have to first get the image on to clipboard programmatically, which I haven't quite sorted out yet. Quote Link to comment
Darren Posted October 27, 2011 Report Share Posted October 27, 2011 Sorry, I didn't mean to offend. I have deep respect for fellow yak-shavers. Maybe some day we can exchange yak-shaving tips, goodness knows I've got a few. As for your scripting question...unfortunately, there is no way to programmatically change the image in a decoration. You have two options that I can think of: 1. If the new image is on the clipboard, you can use the "Paste" method of the TopLevelDiagram class and paste it in the same location as the existing decoration, then delete the old one. 2. If the new image is in a file on disk, then you read it in, and set the value of a picture constant on the diagram instead of a regular decoration. Quote Link to comment
Darin Posted October 27, 2011 Report Share Posted October 27, 2011 There is a way, I'll post my code later when I get to my machine. The steps I take are as follows: Save a VI which contains only a simple placeholder PNG image. I use this as a template, and with some vi.lib gems I replace the MNGI block with new PNG data. Conventional scripting fixes the size of the decoration leaving a subVI with the desired PNG on the BD. I then place this SubVI on the target BD and inline it. Easy peasey. Attempts to paste images conventionally result in bitmaps. Quote Link to comment
jcarmody Posted October 27, 2011 Author Report Share Posted October 27, 2011 Sorry, I didn't mean to offend. No offense was taken I always appreciate injections of humor into these threads. I looked at the video on my phone - Ren & Stimpy... very nice. Quote Link to comment
David_L Posted October 27, 2011 Report Share Posted October 27, 2011 Well here is my bootleg workaround, but it works. Read an Image, load that image into a 2D picture control without a frame, export 2D image control to clipboard. Then in the VI in question delete the image you want to replace and paste the new image to the same location... Not ideal by any means, but it does the trick I believe. I also made the assumption that there was only one image on the block diagram already, and you want to replace it with a PNG. But that's easy enough to fix I'm sure. Change Block Diagram Picture.vi Quote Link to comment
jcarmody Posted October 27, 2011 Author Report Share Posted October 27, 2011 [...] I then place this SubVI on the target BD and inline it. Easy peasey. Attempts to paste images conventionally result in bitmaps. I'm going to guess that this won't work for what I want to do; I need to be able to change the image while the VI is running and I can't imagine LabVIEW letting me inline a SubVI unless it's stopped. What do you think? I'd still like to see your code. Quote Link to comment
Aristos Queue Posted October 28, 2011 Report Share Posted October 28, 2011 Could you just draw the image in a Picture Control and then change what you're drawing there? Or are you actually needing to edit a whole bunch of VIs to change one image for another (like, say, a corporate logo changing) ? Quote Link to comment
jcarmody Posted October 28, 2011 Author Report Share Posted October 28, 2011 (edited) It all started in an NI LabVIEW API Community question about working with probes (here), when I was working on my State Machine Follower RCF plugin. This activity was in my mind when I read an Idea Exchange suggestion that we be able to "View probe values within the code during execution". So, I began writing stuff to insert a Free Label into the block diagram near a wire and have a custom probe send a notification that would update the decoration when the value is updated. I soon realized that I'd need a different probe VI for every data type. and it was suggested that some data types would be difficult to represent in a Free Label so I thought I could use a picture of the probe's control instead. This is why I'm trying to change the picture in a decoration. I want the probe to notify with a picture of its control so a background process can update the decoration on the probed VI's BD. I don't think I can use Darin's suggestion because I won't be able to inline a SubVI while the VI is running, and that's also why I can't use a Picture constant. Darren's first suggestion and David_L's VI seem to be the way I'll need to go. Edited October 28, 2011 by jcarmody Quote Link to comment
David_L Posted October 28, 2011 Report Share Posted October 28, 2011 I didn't realize you were referring to a running VI. I think you'll be out of luck either way because you can't do any kind of scripting on a block diagram that is running. Quote Link to comment
jcarmody Posted October 28, 2011 Author Report Share Posted October 28, 2011 I didn't realize you were referring to a running VI. I think you'll be out of luck either way because you can't do any kind of scripting on a block diagram that is running. Pretty good point, but not completely correct. I just tested your VI with my target VI running and found that the Delete and Paste methods don't work. We are able to update Free Labels when their VIs are running. I guess I'll just have to limit myself to things I can represent in text. One avenue I can explore is to float VIs over the block diagram. 1 Quote Link to comment
vugie Posted October 28, 2011 Report Share Posted October 28, 2011 Pretty good point, but not completely correct. I just tested your VI with my target VI running and found that the Delete and Paste methods don't work. We are able to update Free Labels when their VIs are running. I guess I'll just have to limit myself to things I can represent in text. One avenue I can explore is to float VIs over the block diagram. You could also make a picture out of 1x1 free labels as pixels... 1 Quote Link to comment
David_L Posted October 28, 2011 Report Share Posted October 28, 2011 We are able to update Free Labels when their VIs are running. Well shoot. Looks like I learned something new today. Sorry about that. I wonder what other fun things you can do to a running block diagram... Quote Link to comment
Rolf Kalbermatter Posted October 28, 2011 Report Share Posted October 28, 2011 Well shoot. Looks like I learned something new today. Sorry about that. I wonder what other fun things you can do to a running block diagram... That's not scripting but an intentional feature when properties were introduced. There isn't much else you can do on a running VI if it's not done in a control as data change. Quote Link to comment
jcarmody Posted October 29, 2011 Author Report Share Posted October 29, 2011 You could also make a picture out of 1x1 free labels as pixels... ...or, I could draw in a Free Label using ASCII Art. Quote Link to comment
vugie Posted October 31, 2011 Report Share Posted October 31, 2011 ...or, I could draw in a Free Label using ASCII Art. There is even appropriate library for that... Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.