Graphics

 View Only
  • 1.  Xpression script

    Posted 09-10-2021 11:57

    Does anyone know why this little script does not work. Any obvios mistakes?

    Dim TextObj as xpTextObject
    Dim material as xpMaterial

    Self.GetObjectByName("Text1", TextObj)      (getting the text object)

        Engine.GetMaterialByName("farve_a", material)    (getting the new colour)

    TextObj.SetMaterial(0, material)    (setting the new colour on the textobject)

     
    I'm trying to change the face colour om some text.



    ------------------------------
    Poul Erik
    ------------------------------


  • 2.  RE: Xpression script

    Posted 09-13-2021 10:38
    Hi Poul Erik,

    A material on a text object works somewhat different than a material on another object. Where you actually change the material of a quad with "SetMaterial", it appears you only change the brush on a TextObject using "SetMaterial". This means that the material of the already present text will remain unchanged, but when you add new text to the TextObject the new text will appear using the newly assigned material. Just changing the material of a text object first and then do a "TextObjext.Text =" won't do the trick. I assume that is because using "TextObjext.Text = " will reset the text object back to its default settings, i.e. using the default material again. Using "TextObject.AddLine" will solve this for you. You, however, need to clear the text object first otherwise the new text will be added to the old text (unless that is exactly what you want).

    In the end your code will look something like this:
    dim L_textObject as xpTextObject
    dim L_matColor   as xpMaterial
    dim L_strText    as string
    
    Engine.GetMaterialByName("farve_a", L_matColor)
    Self.GetObjectByName("Text1", L_textObject)
    
    L_strText = L_textObject.Text             ' save the old text first
    L_textObject.Clear                        ' make sure the text object doesn't have text in it
    L_textObject.SetMaterial(0, L_matColor)   ' change the material
    L_textObject.AddLine(L_strText)​           ' add the old text to the text object using the new material


    Kind regards,
    Gerard



    ------------------------------
    Gerard de Vries
    Solution Architect Live Graphics & Virtual Graphics
    EMG
    The Netherlands
    ------------------------------