|
|
Rank: Newbie
 Groups: Member
Joined: 3/9/2010 Posts: 5 Location: US
|
I'm linking an image to a PI workbook page. This is easy enough, but over time, this image will change, so I'm trying to find a way to get the PI workbook page to refresh the image.
An alternate way of doing this would be to write VB to search for the newest image file in a given directory and link that to the workbook.
Any ideas?
|
|
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hi tmm2112, Welcome to the forum. If you are using the "Bitmap" ProcessBook Symbol type on your display to show a linked image (as opposed to an embedded image), then as the image changes and you re-open the display it will show the updated image - providing by updated image it retains the same image name. If you mean that within a folder you always want to display the image file that was last updated then there is a VBA solution. In fact I have been there done that in the past...here is what I used: Code: Sub Test() Call CheckForLatest("C:\ImagesFolder\", ThisDisplay.Symbols("imgUpdate")) End Sub
Sub CheckForLatest(ByVal sDirectory As String, ByVal Image As Bitmap)
Dim FSO As FileSystemObject Dim Fld As Folder, Fs As Files, F As File
Set FSO = New FileSystemObject
If FSO.FolderExists(sDirectory) Then Set Fld = FSO.GetFolder(sDirectory) Set Fs = Fld.Files Dim FileExt As String: FileExt = "" Dim vFileExt As Variant Dim FileName As String: FileName = "" Dim LastModified As Date: LastModified = 0 For Each F In Fs vFileExt = Split(F.Name, ".") FileExt = vFileExt(UBound(vFileExt)) If InStr(1, ".gif|.bmp|.jpg", FileExt) > 1 Then If F.DateLastModified > LastModified Then LastModified = F.DateLastModified FileName = F.Name End If End If Next F Set Fs = Nothing Set Fld = Nothing If Not FileName = "" Then Call Image.Load(FileName, pbImageSizing.pbImageSizingFixed, True) End If End If
Set FSO = Nothing
End Sub
Obviously this can be improved for better checking of file extensions and you need to be aware of the number of files that could slow down the code but you get the idea. Enjoy! Rhys. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie
 Groups: Member
Joined: 3/9/2010 Posts: 5 Location: US
|
Thanks, Rhys. I think you understood my request perfectly. I have a directory of images that are routinely being updated (written over), and I'm looking to have the updated image appear on a display. This is within the PI application, so there may be some changes needed to the commands. I loaded the code today and it threw some errors, so I'm working through it now. But it should work. Thanks for the help and I'll follow up with any modifications that I make.
Mark
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hi Mark, Forgot to mention that you will need to add a reference to Microsoft Scripting Runtime. Probably why the code threw some errors. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie
 Groups: Member
Joined: 3/9/2010 Posts: 5 Location: US
|
RJK Solutions wrote:Hi Mark, Forgot to mention that you will need to add a reference to Microsoft Scripting Runtime. Probably why the code threw some errors. Thanks. I had to do that in the beginning to stop the errors, looked it up somewheres. I am still having some problems with it. There are several references to user defined types that are throwing errors. Since I'm not well schooled in this, it's hard for me to troubleshoot. Could you recommend a good source for learning how to do this; I'm sure it's elementary stuff, but I'm just not up to speed on it. For instance, the line {Call CheckForLatest("x:\AC01\Bad\", ThisDisplay.Symbols("imgUpdate")) } throws a general automation error. I've read up on the help, but it isn't giving me much to go on. Mark
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hi Mark, If you are getting an error on: Code: Call CheckForLatest("x:\AC01\Bad\", ThisDisplay.Symbols("imgUpdate"))
...do you have a Bitmap ProcessBook symbol on your display named "imgUpdate"? For some reading there are a couple of help files that get installed along with ProcessBook that will be useful for you: - ..\PIPC\Help\pipbvb.chm (PI ProcessBook VBA Language Reference) - ..\PIPC\Help\procbook.chm (PI ProcessBook User Guide) There are also some OSI training courses available on ProcessBook/VBA. Oh and don't forget to keep posting back on here  and on vCampus if you have a subscription (you will have access to some online training courses). Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie
 Groups: Member
Joined: 3/9/2010 Posts: 5 Location: US
|
Yep, that was the problem. The program names it "graphic" and I had forgotten to change it. I think I need some of those training courses.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Well I don't know about your circumstances but you might want to see if your employer has some seats for vCampus or will pay for a subscription, you get access to some of the courses in addition to the whitepapers etc in the Library. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
|
Guest
|