Graphics

 View Only
Expand all | Collapse all

Querying Database for Image

  • 1.  Querying Database for Image

    Posted 09-27-2016 05:21
    Pulling from the forum and TheOriginalDave, I have compiled the following script in OnBeforeOnline:

    ' datakey

    dim vari as xpTextObject
    dim keys as xpDatalinqKeys
    dim key as xpDatalinqKey

    'find the text object by name that the key value will come from
    self.GetObjectByName("BasePage", vari)

    'find the keys in the scene and find the specific datalinq key by name
    self.GetDatalinqKeys(keys)
    keys.GetKeyByName("datakey", key)

    'copy the content of the source text field to the datalinq key
    key.AsString = vari.text

    'refresh datalinqs in the scene
    Self.RefreshDatalinqs()


    'image

    dim ImageFile1 as xpTextObject
    dim photo as xpBaseObject
    dim picmat1 as xpMaterial
    dim picshad1 as xpBaseShader
    dim FilePath as String

    Self.GetObjectByName("Image Name", ImageFile1)
    FilePath = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile1.Text + ".png" 'sets the filepath
    Self.GetObjectByName("Picture", Photo) 'gets the quad object
    Photo.GetMaterial(0, picmat1) 'gets the quad's material
    picmat1.GetShader(0, picshad1) 'gets the quad's material's shader
    picshad1.SetFileName(FilePath) 'sets the shader's filepath to the above filepath


    I can populate my text fields just fine with Visual Logic Datalinq blocks, with queries:
    SELECT RaceShortName FROM ENPSElectionRaceProperties WHERE BasePage= %datakey%
    SELECT RaceCandidateDisplayName, RaceCandidatePercentVotes, RaceCandidateVotes FROM ENPSElectionRaceResults where BasePage= %datakey% ORDER BY RaceCandidateVotes DESC


    ...but when I Datalinq'd the text field "ImageFile1" using the query:
    SELECT RaceCandidateImageRef FROM ENPSElectionRaceResults where BasePage= %datakey% ORDER BY RaceCandidateVotes DESC

    I get the name of the image file from the database, but don't get the image script to assigned the FilePath to the shader.

    I tried Datalinqing the texture directly in the material editor, but the datakey didn't seem to function there. (When I included "where BasePage=1, I got my image.)

    Do I have the 'image script in the correct place? I considered adding it the the ImageFile1 OnSetText, but wasn't sure that made sense.

    Also, there is a small problem with the datakey section of the script---when I play to air, the graphic plays and then the Datalinq'd text fields dissolve in.


    Anybody have any ideas?


  • 2.  RE: Querying Database for Image

    Posted 09-27-2016 07:00
    Seems that you forget a \ here, after LocalCandidates : FilePath = "V:\YourVoiceYourVote\LocalCandidates\" + ImageFile1.Text + ".png" 'sets the filepath
    #XPression


  • 3.  RE: Querying Database for Image

    Posted 09-28-2016 01:50
    So, I sat down with IT and found that and a couple of other typos and started using this script in OnBeforeOnline:


    ' datakey

    dim vari as xpTextObject
    dim keys as xpDatalinqKeys
    dim key as xpDatalinqKey

    'find the text object by name that the key value will come from
    self.GetObjectByName("BasePage", vari)

    'find the keys in the scene and find the specific datalinq key by name
    self.GetDatalinqKeys(keys)
    keys.GetKeyByName("datakey", key)

    'copy the content of the source text field to the datalinq key
    key.AsString = vari.text

    'refresh datalinqs in the scene
    Self.RefreshDatalinqs()


    'photo1

    dim ImageFile1 as xpTextObject
    dim photo1 as xpBaseObject
    dim picmat1 as xpMaterial
    dim picshad1 as xpBaseShader
    dim FilePath1 as String

    Self.GetObjectByName("ImageFile1", ImageFile1)
    FilePath1 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile1.Text + ".png" 'sets the filepath
    Self.GetObjectByName("Photo1", Photo1) 'gets the quad object
    Photo1.GetMaterial(0, picmat1) 'gets the quad's material
    picmat1.GetShader(0, picshad1) 'gets the quad's material's shader
    picshad1.SetFileName(FilePath1) 'sets the shader's filepath to the above filepath


    ...and it worked. We cheered and I got back to preparing for the next the show.

    Later, I got back to finishing up the Datalinqs for my other fields---currently a three candidate photo graphic---and added the sections of script below to make the other photos.

    Well, now, I get the same photo three times, although each photo has its respective material applied to it. All the text fields are working correctly, I can see that the correct names are pulled for ImageFile1, ImageFile2 & ImageFile3 text fields, but I only get the first candidate. Also, it works one time, unless I delete the shaders from each material and then recreate/rename them correctly. Then it works one more time...with three of the same candidate.



    'photo2

    dim ImageFile2 as xpTextObject
    dim photo2 as xpBaseObject
    dim picmat2 as xpMaterial
    dim picshad2 as xpBaseShader
    dim FilePath2 as String

    Self.GetObjectByName("ImageFile2", ImageFile2)
    FilePath2 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile2.Text + ".png" 'sets the filepath2
    Self.GetObjectByName("Photo2", Photo2) 'gets the quad object
    Photo2.GetMaterial(0, picmat2) 'gets the quad's material
    picmat2.GetShader(0, picshad2) 'gets the quad's material's shader
    picshad2.SetFileName(FilePath2) 'sets the shader's filepath to the above filepath2

    'photo3

    dim ImageFile3 as xpTextObject
    dim photo3 as xpBaseObject
    dim picmat3 as xpMaterial
    dim picshad3 as xpBaseShader
    dim FilePath3 as String

    Self.GetObjectByName("ImageFile3", ImageFile3)
    FilePath3 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile3.Text + ".png" 'sets the filepath3
    Self.GetObjectByName("Photo3", Photo3) 'gets the quad object
    Photo3.GetMaterial(0, picmat3) 'gets the quad's material
    picmat3.GetShader(0, picshad3) 'gets the quad's material's shader
    picshad3.SetFileName(FilePath3) 'sets the shader's filepath to the above filepath3


    Should the 'photo* sections be in OnBeforeOnline? Somewhere else?

    Will a Datalinq Key work when included in material editor Texture File Datalinq?

    Do I need a script to reset the shaders between versions of the same scene?

    Another problem is that when I play from one version of the scene to another, the old text disappears, then the new text appears.


    #XPression


  • 4.  RE: Querying Database for Image

    Posted 09-29-2016 01:02
    Usually these days people use the xpBaseObject.SetVolatileTextureFile method to assign an image directly to a quad (without needing to modify the shader of a global material). The GetShader/SetFileName is how it was done in older versions of XPression that did not have the SetVolatileTextureFile function.

    It would be something like this:

    Self.GetObjectByName("ImageFile1", ImageFile1)
    FilePath1 = "V:\YourVoiceYourVote\LocalCandidates\" + ImageFile1.Text + ".png" 'sets the filepath
    Self.GetObjectByName("Photo1", Photo1) 'gets the quad object
    Photo1.SetVolatileTextureFile(0, FilePath1)


    Normally I would do this in the OnOnline script. Typically I only use OnBeforeOnline for transition logic type stuff.

    However, in your case there may be problem with doing it in OnOnline. Since you are trying to change a datalinq key in the script as well, when you call RefreshDatalinqs you have to realize that the data being returned from the datalinq server will not be available for a few frames after you call RefreshDatalinqs. By this time, the scene is already online and has run the rest of your script containing the Photo update scripts.

    What I have seen people do in the past is to put the Datalinq key and refresh datalinqs in OnOnline, and then in a script on the scene director on frame 3 or 4, they would put the script to set the volatile textures based on the results of the datalinq query. By the time this script runs the datalinq should have had time to return the updated data. This works only when you can cover up the first few frames of the scene with an animation/transition so you don't see the old pictures before the script and new data have run.

    In the next version of XPression 6.7, there is a new script event called OnPrepare that lets you do all this before the scene goes online so you don't need to cover up the data with an animation.

    #XPression


  • 5.  RE: Querying Database for Image

    Posted 09-29-2016 06:25
    Brian!

    I couldn't work in the control room this evening, so I worked in XpressionDesigner v5.5 build 2722. I started from scratch without the Datalinqs or the Datalinq key. With the script below in OnSceneOnline and OnSceneOffline, I made three text fields pull three images from our mapped drive. Without the script in both places, it failed.

    I packaged it up and brought it to the control room and it worked on XpressionStudio v6.0 build 3326.

    I imported the scene into my full project, matched the script up to my naming conventions, added the scripts to OnSceneOnline & OnSceneOffline in the full-blown graphic and it didn't work. I decided my scene might be corrupted, so I copied all the layers, pasted them into a new scene, copied the scripting and the VisualLogic Datalinqs and the photos didn't work.

    I like the SetVolatileTextureFile approach so I tried it. Self.Get failed to compile in a SceneDirector event script, so I tried Scene.Get, but that didn't work. Plus, I couldn't make the Datalinq Key with that script in OnOnline. I will try again tomorrow, I'm thinking I might be tired and missing something. Next, I'll try pasting all my layers into the scene that does pull the photos.

    I've been looking forward to upgrading to Xpression 6.7, but my IT and I haven't found the time...and won't before a local runoff election on Tuesday. I will find time before the general in November!

    Thanks for all your help,
    James.



    OnSceneOnline & OnSceneOffline:
    'photo

    dim ImageFile as xpTextObject
    dim Photo as xpBaseObject
    dim picmat1 as xpMaterial
    dim picshad1 as xpBaseShader
    dim FilePath1 as String

    Self.GetObjectByName("ImageFile", ImageFile)
    Self.GetObjectByName("Photo", Photo) 'gets the quad object
    Photo.GetMaterial(0, picmat1) 'gets the quad's material
    picmat1.GetShader(0, picshad1) 'gets the quad's material's shader
    FilePath1 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile.Text + ".png" 'sets the filepath1
    picshad1.SetFileName(FilePath1) 'sets the shader's filepath to the above filepath1

    'photo2

    dim ImageFile2 as xpTextObject
    dim Photo2 as xpBaseObject
    dim picmat2 as xpMaterial
    dim picshad2 as xpBaseShader
    dim FilePath2 as String

    Self.GetObjectByName("ImageFile2", ImageFile2)
    Self.GetObjectByName("Photo2", Photo2) 'gets the quad object
    Photo2.GetMaterial(0, picmat2) 'gets the quad's material
    picmat2.GetShader(0, picshad2) 'gets the quad's material's shader
    FilePath2 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile2.Text + ".png" 'sets the filepath1
    picshad2.SetFileName(FilePath2) 'sets the shader's filepath to the above filepath1

    'photo3

    dim ImageFile3 as xpTextObject
    dim Photo3 as xpBaseObject
    dim picmat3 as xpMaterial
    dim picshad3 as xpBaseShader
    dim FilePath3 as String

    Self.GetObjectByName("ImageFile3", ImageFile3)
    Self.GetObjectByName("Photo3", Photo3) 'gets the quad object
    Photo3.GetMaterial(0, picmat3) 'gets the quad's material
    picmat3.GetShader(0, picshad3) 'gets the quad's material's shader
    FilePath3 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile3.Text + ".png" 'sets the filepath1
    picshad3.SetFileName(FilePath3) 'sets the shader's filepath to the above filepath1

    #XPression


  • 6.  RE: Querying Database for Image

    Posted 09-29-2016 15:22
    You should really get your Designer upgraded to the same version as your OnAir system!
    #XPression


  • 7.  RE: Querying Database for Image

    Posted 09-29-2016 19:59
    Wait, why did you put it in OnSceneOnline and OnSceneOffline? It definitely should not go there. OnSceneOnline is not the same as OnOnline.

    It should either go in OnOnline if you are not using the Datalinq Key stuff, or if you are trying to use one datalinq value to modify a datalinq key to re-query the data, then the volatile script needs to be on the scene director.

    #XPression


  • 8.  RE: Querying Database for Image

    Posted 09-30-2016 01:52
    Working in Designer, that was the first combination I found that the script worked when I played them out through the sequence. On Xpression Studio, it will work in OnOnline.

    As you suggested, I moved the Datalinq Key script to OnOnline:


    ' datakey

    dim vari as xpTextObject
    dim keys as xpDatalinqKeys
    dim key as xpDatalinqKey

    'find the text object by name that the key value will come from
    self.GetObjectByName("BasePage", vari)


    'find the keys in the scene and find the specific datalinq key by name
    self.GetDatalinqKeys(keys)
    keys.GetKeyByName("datakey", key)

    'copy the content of the source text field to the datalinq key
    key.AsString = vari.text

    'refresh datalinqs in the scene
    Self.RefreshDatalinqs()



    ...and to pull the photos, I added a script event to the scene director:

    'photos

    dim self

    dim imagefile as xpTextObject
    dim imagefile2 as xpTextObject
    dim imagefile3 as xpTextObject

    dim photo as xpBaseObject
    dim photo2 as xpBaseObject
    dim photo3 as xpBaseObject

    dim filepath1 as string
    dim filepath2 as string
    dim filepath3 as string



    Self.GetObjectByName("ImageFile",ImageFile)
    Self.GetObjectByName("ImageFile2",ImageFile2)
    Self.GetObjectByName("ImageFile3",ImageFile3)

    filepath1 = "V:\YourVoiceYourVote\LocalCandidates"& ImageFile.text & ".png"
    filepath2 = "V:\YourVoiceYourVote\LocalCandidates" & ImageFile2.text & ".png"
    filepath3 = "V:\YourVoiceYourVote\LocalCandidates" & ImageFile3.text & ".png"

    Self.GetObjectByName("Photo",Photo)
    Self.GetObjectByName("Photo2",Photo2)
    Self.GetObjectByName("Photo3",Photo3)

    photo.SetVolatileTextureFile(0, filepath1)
    photo2.SetVolatileTextureFile(0, filepath2)
    photo3.SetVolatileTextureFile(0, filepath3)


    The photos would not load. I tried versions with and without materials applied to the photo quads.

    This script did work in Designer in OnOnline.

    I was still very concerned that my scene might have corrupted elements that might be preventing the script from working and tried everything I could think of to rule that out.

    With scenes that use the GetMaterial,GetShader,SetFileName script in OnSceneOnline & OnSceneOffline:

    'photo

    dim ImageFile as xpTextObject
    dim Photo as xpBaseObject
    dim picmat1 as xpMaterial
    dim picshad1 as xpBaseShader
    dim FilePath1 as String

    Self.GetObjectByName("ImageFile", ImageFile)
    Self.GetObjectByName("Photo", Photo) 'gets the quad object
    Photo.GetMaterial(0, picmat1) 'gets the quad's material
    picmat1.GetShader(0, picshad1) 'gets the quad's material's shader
    FilePath1 = "V:\YourVoiceYourVote\LocalCandidates" + ImageFile.Text + ".png" 'sets the filepath1
    picshad1.SetFileName(FilePath1) 'sets the shader's filepath to the above filepath1


    ...and the Datalinq Key script in OnBeforeOnline:

    ' datakey

    dim vari as xpTextObject
    dim keys as xpDatalinqKeys
    dim key as xpDatalinqKey

    'find the text object by name that the key value will come from
    self.GetObjectByName("BasePage", vari)


    'find the keys in the scene and find the specific datalinq key by name
    self.GetDatalinqKeys(keys)
    keys.GetKeyByName("datakey", key)

    'copy the content of the source text field to the datalinq key
    key.AsString = vari.text

    'refresh datalinqs in the scene
    Self.RefreshDatalinqs()


    It seems that the Datalinqs feeding my ImageFile text fields were preventing the script from running.

    If I unhook the Datalinq blocks in Visual Logic, and typed in the filenames I wanted in the XpressionStudio sequence, the script pulled the photos correctly.
    #XPression


  • 9.  RE: Querying Database for Image

    Posted 09-30-2016 13:34
    In the scene director script, you need to use scene.GetObjectByName instead of Self.GetObjectByName. When you do "dim self" that is just creating an empty variable not connected to anything, so the script will just exit at that point.

    At this point, I think it would be easier if you upload your scene, database, images, and datalinq config file.. I'm not clear on why you have Datalinq blocks in visual logic? That is probably also part of the problem here.
    #XPression


  • 10.  RE: Querying Database for Image

    Posted 09-30-2016 23:47
    Brian,

    I changed the self.get to scene.get and it worked one time. I've packaged everything up and hope I shared it with you and PeterP on DropBox

    Thanks for taking the time to look this over,
    James.
    #XPression


  • 11.  RE: Querying Database for Image

    Posted 10-03-2016 13:34
    I took a quick look at the project but was confused by why you are trying to take the value from the BasePage text object and copy it to the "datakey" datalinq key. I expected you were doing this because BasePage would be datalinq'd but it was not, it was set to static text.
    #XPression


  • 12.  RE: Querying Database for Image

    Posted 10-03-2016 13:44
    BasePage is a unique reference number within individual races in the ENPS election. Producer would enter it in the template and Datalinqs populate the race details and results. I believe that part of the scene works. The photos are the problem when the ImageFile text objects are Datalinq'd.
    #XPression


  • 13.  RE: Querying Database for Image

    Posted 10-03-2016 13:53
    All the Datalinqs should be within Visual Logic.
    #XPression


  • 14.  RE: Querying Database for Image

    Posted 10-03-2016 14:40
    BasePage is not being set from Datalinq, correct? If not, then why not just have the producer type it directly into the datalinq key instead of having them type it into BasePage. It would save a lot of complications and eliminate the need for the OnOnline script entirely.
    #XPression


  • 15.  RE: Querying Database for Image

    Posted 10-03-2016 14:50
    I built this based on work of a sister station and this thread "Using Scripting to Change Database Query." If there is a simpler, less problematic approach, I am all for it. I didn't realize I could publish a Datalinq key to my Xpression plugin.
    #XPression


  • 16.  RE: Querying Database for Image

    Posted 10-05-2016 13:51
    I modified your sample to simplify it quite a bit and sent it back to you in a private message.
    #XPression