Jump to content

Scripting access to the picture in a BD decoration


jcarmody

Recommended Posts

post-7534-0-86432000-1319722505.png

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

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

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...

post-26442-0-54047600-1319733126_thumb.p

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

Link to comment

[...] 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.

Link to comment

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 by jcarmody
Link to comment

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.

  • Like 1
Link to comment

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...

  • Like 1
Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.