Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2015 11:52
Show Gist options
  • Save zeffii/46dba5bd901e97fbea07 to your computer and use it in GitHub Desktop.
Save zeffii/46dba5bd901e97fbea07 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 update_object(obj, context):
b = obj.textmat_addon
for i, character in enumerate(
tval = getattr(b, "char_" + str(i))
if tval >= len(obj.material_slots):
tval = len(obj.material_slots) - 1
character.material_index = tval
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)
obj = context.object
if obj.textmat_addon.use_me:
update_object(obj, context)
def text_updater(scene):
for obj in
if obj.type == 'FONT':
if obj.textmat_addon.use_me:
update_object(obj, bpy.context)
class TextualProperties(bpy.types.PropertyGroup):
use_me = bpy.props.BoolProperty()
for i in range(80):
exec("char_{0} = IntProperty(min=0, max=90, options={{\'ANIMATABLE\'}}, 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
col.prop(props_addon, 'use_me', toggle=True)
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