YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Linking or embeding images Options · View
tmm2112
#1 Posted : Tuesday, March 09, 2010 8:07:41 PM
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?
Sponsor  
 

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.
RJK Solutions
#2 Posted : Tuesday, March 09, 2010 9:35:05 PM
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
tmm2112
#3 Posted : Wednesday, March 10, 2010 9:28:20 PM
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
RJK Solutions
#4 Posted : Thursday, March 11, 2010 8:16:04 PM
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
tmm2112
#5 Posted : Sunday, March 14, 2010 6:15:11 PM
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
RJK Solutions
#6 Posted : Tuesday, March 16, 2010 10:18:37 AM
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 BigGrin 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
tmm2112
#7 Posted : Friday, March 19, 2010 1:31:23 PM
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.
RJK Solutions
#8 Posted : Tuesday, March 23, 2010 4:19:38 PM
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
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.