Page 1 of 1

Lua - change font in TextPlus - Help!

PostPosted: Fri May 19, 2017 4:12 pm
by Ziggy Uszkurat
Hi there,

I'm trying to programatically change the font in Text+ using a lua script. However, I can't find the Font Attribute. Can anyone point me in the right direction?

TIA
Ziggx

Re: Lua - change font in TextPlus - Help!

PostPosted: Fri May 19, 2017 5:07 pm
by Chad Capeland
Text1.Font = "Wingdings" works for me

Re: Lua - change font in TextPlus - Help!

PostPosted: Fri May 19, 2017 5:28 pm
by Ziggy Uszkurat
Thanks Chad - can you tell me how to query the current font name in a Text+? I'm new to lua and the developer manuals a little spartan on detail.

TIA
Ziggy

Re: Lua - change font in TextPlus - Help!

PostPosted: Fri May 19, 2017 5:31 pm
by Ziggy Uszkurat
Aah - just figured out. Thanks anyway.

Re: Lua - change font in TextPlus - Help!

PostPosted: Fri May 19, 2017 9:10 pm
by Sander de Regt
Do you mind sharing what you found? It may help people who stumble across this thread as well.

Re: Lua - change font in TextPlus - Help!

PostPosted: Sun May 21, 2017 3:27 pm
by Ziggy Uszkurat
Hi Sander,

I'm only just dipping into lua so there is probably a "right" way to do this, rather than my kludge - I needed to programatically change the font, font size and line spacing in a pre-existing comp. I put the following into a lua script with the extension .lua.scriptlib in the scripts/comp folder so it would run automatically when I opened a comp.
Code: Select all
-- get a list of Text+
texts=comp:GetToolList(false,"TextPlus")
   count=0
   for i, tool in pairs(texts) do
   -- do I need to do this?
   old=tool
   -- check to see if it has the font we want to change...
   if (old:GetInput("Font")=="High Sans Serif 7") then
      -- if yes, then change font, size and line spacing
      old.Font="PRST"
      old.Size=0.075
      old.LineSpacing=1.0
   end


That's it folks!