Graphics

 View Only
  • 1.  Setting font material without using tags

    Posted 11-20-2023 11:10

    I'm trying to set the color of a font's material without using tags.  I have a project where multiple fonts in different scenes will change color based on a selected style.  The goal is to create a single font where the size, leading, and kerning are set and a script will change the color.  I'm trying to avoid creating multiple fonts for a scene, where I would them have to update each font if there is change.  I have a script that I'm testing, but so far it is not working.  Any help would be appreciated, thank you!

    dim txtStyle as xpTextObject
    dim fontTitle as xpFont
    dim fontStyle as xpFontLayerAttrib
    Engine.GetFontByName("FS Title", fontTitle)
    Self.GetObjectByName("Style", txtStyle)
    fontTitle.GetLayerAttribByName("Face", fontStyle)
    fontStyle.GetMaterial(matFont)
    If (txtStyle.Text = "Blue" OR txtStyle.Text = "Elections") Then
    fontStyle.ColorDiffuse.Update(0,47,124,100)
    Else If txtStyle.Text = "Red" Then
    fontStyle.ColorDiffuse.Update(156,2,1,100)
    Else If txtStyle.Text = "Sports" Then
    fontStyle.ColorDiffuse.Update(80,94,101,100)
    End If



    ------------------------------
    John Robbins
    Graham Media Group INC
    ------------------------------


  • 2.  RE: Setting font material without using tags

    Posted 11-20-2023 12:01

    Instead of using "Engine.GetFontByName" try using "Self.Project.GetFontByName".

    If that change works, I cannot explain why it does; it just does. It fixed a problem when I was making materials.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 3.  RE: Setting font material without using tags

    Posted 11-22-2023 09:03

    Thank you for the suggestion.  I tried that with no luck.



    ------------------------------
    John Robbins
    Graham Media Group INC
    ------------------------------



  • 4.  RE: Setting font material without using tags

    Posted 11-22-2023 09:24

    You are setting the ColorDiffuse on the fontLayer, not the material. Also, your material is not declared.

    dim txtStyle as xpTextObject
    dim fontTitle as xpFont
    dim fontStyle as xpFontLayerAttrib
    dim matFont as xpMaterial
    Self.Project.GetFontByName("FS Title", fontTitle)
    Self.GetObjectByName("Style", txtStyle)
    fontTitle.GetLayerAttribByName("Face", fontStyle)
    fontStyle.GetMaterial(matFont)
    If (txtStyle.Text = "Blue" OR txtStyle.Text = "Elections") Then
    matFont.ColorDiffuse.Update(0,47,124,100)
    Else If txtStyle.Text = "Red" Then
    matFont.ColorDiffuse.Update(156,2,1,100)
    Else If txtStyle.Text = "Sports" Then
    matFont.ColorDiffuse.Update(80,94,101,100)
    End If

    Use Self.Project instead of Engine because Engine can affect materials from one Scene to another.

    Fingers crossed.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 5.  RE: Setting font material without using tags

    Posted 11-22-2023 09:57

    Thank you.  You're right in that I forgot to declare the material.  However, upon further testing I found that the "Face" attribute does not seem to be setting the material.  I can declare the other font attributes (border, neon, stroke, shadow) and see the color change as expected, but the "Face" attribute does not set.  Update code below.  Note ".Enabled" and ".Size" were used to test the other attributes to verify the code was working.

    dim txtStyle as xpTextObject
    dim fontTitle as xpFont
    dim fontStyle as xpFontLayerAttrib
    dim matFont as xpMaterial
    Self.Project.GetFontByName("FS Title", fontTitle)
    Self.GetObjectByName("Style", txtStyle)
    fontTitle.GetLayerAttribByName("Face", fontStyle)
    'fontStyle.Enabled = True
    'fontStyle.Size = 50
    fontStyle.GetMaterial(matFont)
    If (txtStyle.Text = "Normal" OR txtStyle.Text = "Elections") Then
    matFont.ColorDiffuse.Update(0,47,124,100)
    Else If txtStyle.Text = "Breaking" Then
    matFont.ColorDiffuse.Update(156,2,1,100)
    Else If txtStyle.Text = "Sports" Then
    matFont.ColorDiffuse.Update(80,94,101,100)
    End If


    ------------------------------
    John Robbins
    Graham Media Group INC
    ------------------------------



  • 6.  RE: Setting font material without using tags

    Ross Staff
    Posted 11-22-2023 10:00

    could you just grab the font material by its name and then just adjust it like you would any other material? 



    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 7.  RE: Setting font material without using tags

    Posted 11-22-2023 15:14

    I figured out what was happening.  At one point I had multiple layers, one for each selectable style, in the font's face thinking I would use the ".Enable" command.  Removing the extra layers resolved the issue.  My final script is below.  Thank you everyone for your help!

    dim txtStyle as xpTextObject
    dim fontTitle as xpFont
    dim fontStyle as xpFontLayerAttrib
    dim matFont as xpMaterial
    Self.Project.GetFontByName("FS Title", fontTitle)
    Self.GetObjectByName("Style", txtStyle)
    fontTitle.GetLayerAttribByName("Face", fontStyle)
    fontStyle.GetMaterial(matFont)
    If (txtStyle.Text = "Normal" OR txtStyle.Text = "Elections") Then
         matFont.ColorDiffuse.Update(0,47,124,100)
    Else If txtStyle.Text = "Breaking" Then
         matFont.ColorDiffuse.Update(156,2,1,100)
    Else If txtStyle.Text = "Sports" Then
         matFont.ColorDiffuse.Update(80,94,101,100)
    End If


    ------------------------------
    John Robbins
    Graham Media Group INC
    ------------------------------



  • 8.  RE: Setting font material without using tags

    Posted 11-22-2023 15:31

    This is just a matter of programming style, but VB does have a switch/case option called select/case. The difference is it looks like it does not have "fall through". It can be more graceful and easier to read.

    https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 9.  RE: Setting font material without using tags

    Ross Staff
    Posted 11-22-2023 17:51

    Engine.GetThingByName targets the Active project loaded in XPression - the Project that is in bold in the in the 'Project Manager' list inside XPression. 

    XPression can load multiple projects at once, but only one can be active. You can make a Project Active by double clicking it or by using Engine.SetActiveProject

    Self.Project.GetThingByName looks in the same project as the one that contacts the scene/script. 

    Every Project has unique scenes, materials, fonts and widgets. So XPression needs to know where to look for something when multiple projects are loaded. 

    XPression MOS and Tessera workflows will often load multiple projects at once, so using Self.Project ensures your script run on the correct references. 

    Manually driven workflows usually only load one project at a time, but it depends. Master control and channel automation workflows sometimes use multiple projects and sometimes don't. 

    For maximum compatibility with all workflows, it's probably best practice to just always use Self.Project.