Graphics

 View Only
Expand all | Collapse all

How to change datalinq-ed image based on text in field from XML?

  • 1.  How to change datalinq-ed image based on text in field from XML?

    Posted 06-05-2014 17:24
    Hello,

    Is there a way to display an image, if its filename is based on what is appearing in a field populated by XML? For example, either LIB, PC, NDP or GRN could show up as party names, from the XML. Is there a way to have a LIB.png/PC.png/NDP.png etc. show up, via scripting of some kind, depending on what is currently being sent via XML?

    I figured that the XML file for our election, that was sent earlier, had a set-in-stone order of candidates - now that the test XML feed is running, the candidates are automatically being reordered, first candidate has the most votes. I had made a datalinq CSV file with image pathnames that corresponded to the candidate order in this original XML, now it won't work.

    So one of our problems was solved, and more were created in the process. But that's the way it goes I guess

    Thanks!


  • 2.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-05-2014 23:25
    Yes, you could create 3 materials for the parties and name the materials LIB, PC, and NDP. Then create a hidden text object for each candidate that you will datalink to the party field. A script in the OnOnline event for each hidden text object (or it could be in OnSetText but the script would need to be different) would then be used to assign the correct material to a quad for each candidate.

    It would be something like this in OnOnline (loops over 3 candidates)



    dim i as integer

    dim party as xpTextObject

    dim quad as xpBaseObject

    dim mat as xpMaterial

    ' loop over 3 candidates

    for i = 1 to 3

    self.GetObjectByName("Party" & i, party)

    self.GetObjectByName("Quad" & i, quad)

    if engine.GetMaterialByName(party.text, mat) then

    quad.SetMaterial(0, mat)

    end if

    next



    #XPression


  • 3.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-05-2014 23:38
    Thankyou so much, I'll give that a try.

    #XPression


  • 4.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-06-2014 16:07
    I'm looking at the script editor, and I don't see OnOnline, I see OnSetText, OnAddText, and OnSetLine. Is that what you meant?

    #XPression


  • 5.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-06-2014 16:13
    No. You need to right click on the scene thumbnail in the scene manager and choose edit script events.

    You probably right clicked on a text object, so you are editing the script for a specific object. You need to edit the script for the overall scene.

    #XPression


  • 6.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-06-2014 17:28
    That's exactly what I had done, I had clicked on the text object.

    Now it works perfectly! Thanks!

    #XPression


  • 7.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-06-2014 19:18
    Okay - I'm being asked for something else... our candidate names come in 2 fields, Firstname and Lastname. How would I take the first initial of the first name, a period, a space, and then the last name, and put it into one field?

    #XPression


  • 8.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-07-2014 13:02
    This will loop over 3 candidates and look for hidden objects "FirstName1", "LastName1", "FirstName2", etc and copy them to "Combined1", "Combined2", etc.. Put it in OnOnline.

    dim firstname as xpTextObject

    dim lastname as xpTextObject

    dim combined as xpTextObject

    dim i as integer

    for i = 1 to 3

    self.GetObjectByName("FirstName" & i, firstname)

    self.GetObjectBYName("LastName" & i, lastname)

    self.GetObjectByName("Combined" & i, combined)

    combined.text = firstname.text(0) & ". " & lastname.text

    next



    #XPression


  • 9.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-09-2014 19:43
    So I have combined both scripts in the one page, and I renamed the 2nd script's for-next variable as "j" because "i" was already used in the previous script.

    I have left the invisible fields visible for now, to see how everything is working. In the Combined fields, I am only getting last names in fields 2-4. For the first candidate, the Firstname field populates, then it puts an initial and no last name in the first Combined field. Any thoughts on what is going wrong? Thanks!

    So here is what I have presently in the OnOnline script area:

    dim i as integer

    dim party as xpTextObject

    dim quad as xpBaseObject

    dim mat as xpMaterial

    ' loop over 4 candidates

    for i = 1 to 4

    self.GetObjectByName("Party" & i, party)

    self.GetObjectByName("PartyLogo" & i, quad)

    if engine.GetMaterialByName(party.text, mat) then

    quad.SetMaterial(0, mat)

    end if

    next

    dim firstname as xpTextObject

    dim lastname as xpTextObject

    dim combined as xpTextObject

    dim j as integer

    for j = 1 to 4

    self.GetObjectByName("FirstName" & j, firstname)

    self.GetObjectByName("LastName" & j, lastname)

    self.GetObjectByName("Combined" & j, combined)

    combined.text = firstname.text(0) & ". " & lastname.text

    next

    #XPression


  • 10.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-09-2014 19:46
    Your script looks correct.

    Can you send a link to your project and data so we could see what is wrong?

    #XPression


  • 11.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-09-2014 21:11
    It's working now.

    I was getting the project ready to save and post somewhere, then it started working perfectly. I might have done something wrong with the sequence, so that the %relid% wouldn't work, or the folks who are sending the test XML had changed something.

    Either way, it works now, and I'm very happy with it. Thanks for your help, Brian!

    #XPression


  • 12.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-09-2014 21:12
    Cool.. The only potential problem I could see would be if a candidate doesn't have a "firstname" in the data source that might cause everything to fail...

    #XPression


  • 13.  RE: How to change datalinq-ed image based on text in field from XML?

    Posted 06-09-2014 22:05
    something like this might be better to handle the no firstname case..



    if len(firstname.text) > 0 then

    combined.text = firstname.text(0) & ". " & lastname.text

    else

    combined.text = lastname.text

    end if



    #XPression