Graphics

 View Only
  • 1.  Chaging Font Color/Material via API

    Posted 04-23-2013 14:44
    Hi all,

    I am trying to take a scene that has a bunch of text objects, each with a different font assigned. My goal is to change the color of the font for a given text object. I've tried to create fonts and change the CurrentFont property (clearing the Text property first, assigning the new font, and reinstating the Text value), but nothing has worked. I've also tried the SetMaterial method on the text object, also to no avail.

    Am I missing something? To give a little more background, I have a hidden text object that is fed by a DataLinq. Based on the value of the hidden object (a color name), it will determine which font or material to assign to the text object when the scene runs. Any info would really help out !

    Thanks!!

    chris


  • 2.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 15:02
    You'll want to set the font using 'textwithtags' combined with 'if' statements. The tags look like {FONT NAME} or {FONT INDEX}.

    examples:

    (font name)

    yourTextObject.textwithtags="{Red Font} (R) {White Font} Jack Jornson"

    (font index)

    yourTextObject.textwithtags="{1} (R) {0} Jack Jornson"

    There is another way that can be found here

    http://community.rossvideo.com/communities/xpression-cg-graphic-system/forum/topic/scripting-font-changes/

    #XPression


  • 3.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 15:08
    Thanks for the reply!

    I just tried this, and it's still not showing me what I want.

    In the OnSetText event of a TextObject, I am doing some parsing of the text (it's url encoding that I am removing). I end up with the variable sOutput as my final text.

    At the end of the script, I have:

    Text = ""

    Self.textwithtags = "{BigYellow} " & sOutput

    The output of the scene shows the urlencoded text in the original font.

    (I am on v4.0 build 2025 if that matters; I don't even see the textwithtags property in the API I am referencing).

    #XPression


  • 4.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 15:13
    Try:

    Self.textwithtags = "{BigYellow}"+ sOutput

    #XPression


  • 5.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 15:16
    Same result.

    When I use Self.textwithtags "{BigYellow}" + sOutput, I get the original text (still url encoded) and the original font.

    #XPression


  • 6.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 15:53
    I haven't had any luck dynamically changing a text object's own text. I haven't experimented with it too much though. I put my script on the hidden textobject with the datalinq and use it to change my main textobject. This could solve your url problem.

    I'd suggest doing a quick test. In a new scene create two text objects. On the first object type "blue" and add a script.

    Scene.getObjectByName("YOUR_2ND_TEXT_OBJECT_NAME", mainTextObject)

    if Text="blue" then

    mainTextObject.textwithtags="{0} test test test"

    else

    mainTextObject.textwithtags="{1} test test test"

    end if

    If that works then you will know that textwithtags is working and that your problem came from trying to dynamically change a text layers own text.

    EDIT: Changed text tags to index numbers.

    #XPression


  • 7.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 16:45
    I think the problem may be the textwithtags assignment.

    In the OnOnline event of the entire Scene, I used:

    Dim OTP as xpTextObject

    Self.GetObjectByName("On the phone",OTP)

    OTP.textwithtags="{1} On the phone"

    Followed by a script to change a picture in another quad.

    When I run the scene, the font does not change, and all script after the OTP.textwithtags statement does not execute. If I comment out the OTP.textwithtags line only, then the entire script runs.

    I am also trying to get the material of the font object to directly change it's xpMaterial.DiffuseColor values (color.R, color.G, color.B), and that isn't working either. Running out of ideas! :)

    #XPression


  • 8.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 17:07
    I just tried that setup and it worked fine. Perhaps "On the phone" doesn't match your text object name? That was the only way I found to break the script while still compiling without any errors.

    I'm using version 4.1 but I wouldn't expect the script to compile if the build mattered.

    Unfortunately, I haven't scripted a material so I don't know anything about that yet.

    #XPression


  • 9.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 17:48
    I am positive that I am referencing the proper object; I reset the text of the object first to make sure I have the reference.

    The only difference I can see is the build number; I am still on 4.0. Maybe the textwithtags was introduced in 4.1; I can't find that property anywhere in the API docs for 4.0.

    I'll look into getting the next upgrade.

    Thanks so much for all of your help!!

    Chris

    #XPression


  • 10.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 17:57
    No problem. I'm just sorry I couldn't help more.

    #XPression


  • 11.  RE: Chaging Font Color/Material via API

    Posted 04-23-2013 20:44
    Textwithtags was added in XPression 4.1, and we will be upgrading Chris to 4.1 so he can use them!

    #XPression