# Is it possible to animate which characters of a text object are assigned to a material?

Is it possible to animate which materials are assigned to specific characters in a text object? It is quite easy to assign the materials how I want using this method, but I do not know of a way to animate it. Is this possible at this point? And if not, is there a workaround using different techniques that I could use?

This question is similar to this question and this question, I just want to know if there are other methods that could be used for text objects.

..but if it can be scripted it can be animated, either via a driver or a frame_change event handler, or Sverchok / Animation Nodes and their Scripted Nodes.

import bpy
import random

for character in bpy.data.objects['Text'].data.body_format:
character.material_index = random.choice([0, 1])

''' more options per character '''
# character.use_bold
# character.use_italic
# character.use_small_caps
# character.use_underline


This loops through all characters in the body of the Font Object (even non-visible characters) and set their material_index to 0 or 1. Material_Indices and Material_Slots are explained here (Both Cycles and Blender Internal render use the same convention)

Yes this is not super convenient if you aren't comfortable with writing scripts, i'm guessing there aren't many requests for easy ways to do this.

## As a Driver

import math
import random

import bpy

def driver_func(animation_state):
for i, character in enumerate(bpy.data.objects['Text'].data.body_format):
if i < animation_state:
character.material_index = 0
else:
character.material_index = 1
return 0