picture home | art | events | music | rack extensions | downloads | pixel blog

omino pixel blog

pixels, motion, and scripting
david van brink // Fri 2023.09.8 21:26 // {after effects}

OminoLuaNote[4]: Fonts and Files

This omino lua script shows two features. First, how to load a font file with ca:addFont(path). If successful, returns an integer zero or greater which is the index to use in ca:textSetFont(). If unsuccessful, -1.

Second, it shows how to read a text file into a lua string variable. The script here prints the beginning of the string, increasing by frame number.

The rendered video below shows the parameters animated. In the case of text size, it doesn’t animate very smoothly! (The text renderer snaps to pixels for better readability.) So if you want an animated text size, better to resize the whole layer.

function render(ca, cv)
  local fi = ca:addFont('/Library/Fonts/LithosPro-black.otf')
  local sz = cv.float0
  if sz < 10 then sz = 10 end

  local s = omReadFile('/Users/poly/Desktop/swText.txt')
  s = string.sub(s,1, cv.frame)


function updateControls(cn, cv)
  cn.float0 = 'fontSize'
  cn.float1 = 'textRotation'
  cn.point0 = 'textPoint'
oh, i dont know. what do you think?

david van brink // Wed 2023.09.6 12:56 // {after effects}

OminoLuaNote[3]: Builtin Values

omino lua provides several useful builtin values. They are in the two arguments of the render() function. The first argument, the canvas, is responsible for drawing text and graphics, and has graphical information. The second argument, the control values, has the visible sliders and checkboxes and such, plus a few extras.

function render(ca, cv)
  local sz = 22
  ca:textSetPoint(10, sz + 10)

  ca:textPrint(sprintf(' width: %d\n', ca.width))
  ca:textPrint(sprintf(' height: %d\n', ca.height))
  ca:textPrint(sprintf(' frame: %d\n', cv.frame))
  ca:textPrint(sprintf(' time: %f\n', cv.time))
  ca:textPrint(sprintf(' fps: %f\n', cv.fps))
  ca:textPrint(sprintf(' project path: %s\n', cv.projectPath))
  ca:textPrint(sprintf(' version: %s\n', cv.version))

  local pp = cv.projectPath
  local lastSlash = string.find(pp, '/[^/]*$')
  local lastDot = string.find(pp, '%.[^%.]*$')
  local dir = string.sub(pp, 1, lastSlash)
  local file = string.sub(pp, lastSlash+1)
  local name = string.sub(pp, lastSlash+1,lastDot-1)

  ca:textPrint(sprintf(' dir: %s\n', dir))
  ca:textPrint(sprintf(' file: %s\n', file))
  ca:textPrint(sprintf(' name: %s\n', name))

Here we see that ca.width and ca.height have the dimensions of the solid layer that has the effect. Cooridnates in omino lua are always at natural resolution, even when rendering is downsampled by half or more.

And cv, the control values, has the current frame and time within the layer (not the comp), and the frame rate.

We can also see the project path here. That’s maybe nice for watermarking your renders or something. But it will also be useful for data-driven projects where you provide a data file, and want to keep it next to your After Effects project file. Oh yes, omino lua can read files!

Lastly, we see an example of Lua’s regular expressions, lastDot = string.find(pp, ‘%.[^%.]*$’). This looks for a dot, followed by not-dots until the end of the line. Lua’s REs differ from many by using the percent-sign as the literal escape, and indexes start from 1, and ranges are inclusive.

oh, i dont know. what do you think?

(c) 2003-2023 omino.com / contact poly@omino.com