Skip to content

Instantly share code, notes, and snippets.

Last active December 17, 2015 10:53
Show Gist options
  • Save zeffii/1173f780f8520ced75a8 to your computer and use it in GitHub Desktop.
Save zeffii/1173f780f8520ced75a8 to your computer and use it in GitHub Desktop.
import bpy
from bpy.props import IntProperty
Usage, run the script to add character properies to bpy.types.Object
The UI appears in 3dview Tools, as MISC. You'll get a direct mapping between
character and material index (based on material_slots).
You can set keyframes using the sliders, and you can render / playback the
material updates because of the added frame_change event handler.
def charmat_update(self, context):
# this is used for the visual feedback when adjusting sliders
# and this is also called by the framechange event to update the
# material per character (unless there's a neater way to do this)
b = context.object.textmat_addon
for i, character in enumerate(['Text'].data.body_format):
tval = getattr(b, "char_" + str(i))
if tval >= len(context.object.material_slots):
tval = len(context.object.material_slots) - 1
character.material_index = tval
def text_updater(scene):
charmat_update('uchhhh', bpy.context)
class TextualProperties(bpy.types.PropertyGroup):
for i in range(80):
exec("char_{0} = IntProperty(min=0, max=90, update=charmat_update)".format(i))
class CustomPanel(bpy.types.Panel):
"""A Custom Panel in the Viewport Toolbar"""
bl_label = "Generate"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def poll(self, context):
if context.object and context.object.type == 'FONT':
if context.object.mode == 'OBJECT':
return True
def draw(self, context):
layout = self.layout
col = layout.column()
body =
props_addon = context.object.textmat_addon
for i in range(len(body)):
row = col.row()
row.prop(props_addon, 'char_' + str(i), text="")
def register():
bpy.types.Object.textmat_addon = bpy.props.PointerProperty(type=TextualProperties)
handler =
if not (text_updater in handler):
def unregister():
del bpy.types.Object.textmat_addon
handler =
for func in reversed(handler):
if func.__name__ == 'text_updater':
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment