Paste Code
Paste Blends
Paste Images
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8-80 compliant>
import bpy
from bpy.app.handlers import persistent

bl_info = {
'name': 'Typewriter Text',
'author': 'Bassam Kurdali',
'version': '0.1',
'blender': (2, 6, 5),
'location': 'Properties Editor, Text Context',
'description': 'Typewriter Text effect',
'url': 'http://urchn.org',
'category': 'Text'}

__bpydoc__ = """
Typewriter Text Animation For Font Objects

"""


def uptext(text):
'''
slice the source text up to the character_count
'''
source = text.source_text
if source in bpy.data.texts:
text.body = bpy.data.texts[source].as_string()[:text.character_count]
else:
text.body = source[:text.character_count]


@persistent
def typewriter_text_update_frame(scene):
'''
sadly we need this for frame change updating
'''
for text in scene.objects:
if text.type == 'FONT' and text.data.use_animated_text:
uptext(text.data)


def update_func(self, context):
'''
updates when changing the value
'''
uptext(self)






class TEXT_PT_Typewriter(bpy.types.Panel):
'''
Typewriter Effect Panel
'''
bl_label = "Typewriter Effect"
bl_idname = "TEXT_PT_Typewriter"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'data'

@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'FONT'

def draw_header(self, context):
text = context.active_object.data
layout = self.layout
layout.prop(text, 'use_animated_text', text="")

def draw(self, context):
st = context.space_data
text = context.active_object.data
layout = self.layout
layout.prop(text,'character_count')
layout.prop(text,'source_text')


def register():
'''
addon registration function
'''
# create properties
bpy.types.TextCurve.character_count = bpy.props.IntProperty(
name="character_count",update=update_func, min=0, options={'ANIMATABLE'})
bpy.types.TextCurve.backup_text = bpy.props.StringProperty(
name="backup_text")
bpy.types.TextCurve.use_animated_text = bpy.props.BoolProperty(
name="use_animated_text", default=False)
bpy.types.TextCurve.source_text = bpy.props.StringProperty(
name="source_text")
# register the module:
bpy.utils.register_module(__name__)
# add the frame change handler
bpy.app.handlers.frame_change_post.append(typewriter_text_update_frame)


def unregister():
'''
addon unregistration function
'''
# remove the frame change handler
bpy.app.handlers.frame_change_post.remove(typewriter_text_update_frame)
# remove the properties
# XXX but how???
# remove the panel
bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. #  This program is free software; you can redistribute it and/or
  4. #  modify it under the terms of the GNU General Public License
  5. #  as published by the Free Software Foundation; either version 2
  6. #  of the License, or (at your option) any later version.
  7. #
  8. #  This program is distributed in the hope that it will be useful,
  9. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #  GNU General Public License for more details.
  12. #
  13. #  You should have received a copy of the GNU General Public License
  14. #  along with this program; if not, write to the Free Software Foundation,
  15. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. # <pep8-80 compliant>
  20. import bpy
  21. from bpy.app.handlers import persistent
  22.  
  23. bl_info = {
  24.     'name': 'Typewriter Text',
  25.     'author': 'Bassam Kurdali',
  26.     'version': '0.1',
  27.     'blender': (2, 6, 5),
  28.     'location': 'Properties Editor, Text Context',
  29.     'description': 'Typewriter Text effect',
  30.     'url': 'http://urchn.org',
  31.     'category': 'Text'}
  32.  
  33. __bpydoc__ = """
  34. Typewriter Text Animation For Font Objects
  35.  
  36. """
  37.  
  38.  
  39. def uptext(text):
  40.     '''
  41.    slice the source text up to the character_count
  42.    '''
  43.     source = text.source_text
  44.     if source in bpy.data.texts:
  45.         text.body = bpy.data.texts[source].as_string()[:text.character_count]
  46.     else:
  47.         text.body = source[:text.character_count]
  48.  
  49.  
  50. @persistent  
  51. def typewriter_text_update_frame(scene):
  52.     '''
  53.    sadly we need this for frame change updating
  54.    '''
  55.     for text in scene.objects:
  56.         if text.type == 'FONT' and text.data.use_animated_text:
  57.             uptext(text.data)
  58.  
  59.  
  60. def update_func(self, context):
  61.     '''
  62.    updates when changing the value
  63.    '''
  64.     uptext(self)
  65.    
  66.        
  67.  
  68.  
  69.  
  70.  
  71. class TEXT_PT_Typewriter(bpy.types.Panel):
  72.     '''
  73.    Typewriter Effect Panel
  74.    '''
  75.     bl_label = "Typewriter Effect"
  76.     bl_idname = "TEXT_PT_Typewriter"
  77.     bl_space_type = 'PROPERTIES'
  78.     bl_region_type = 'WINDOW'
  79.     bl_context = 'data'
  80.  
  81.     @classmethod
  82.     def poll(cls, context):
  83.         return context.active_object and context.active_object.type == 'FONT'
  84.  
  85.     def draw_header(self, context):
  86.         text = context.active_object.data
  87.         layout = self.layout
  88.         layout.prop(text, 'use_animated_text', text="")
  89.  
  90.     def draw(self, context):
  91.         st = context.space_data
  92.         text = context.active_object.data
  93.         layout = self.layout
  94.         layout.prop(text,'character_count')
  95.         layout.prop(text,'source_text')
  96.  
  97.  
  98. def register():
  99.     '''
  100.    addon registration function
  101.    '''
  102.     # create properties
  103.     bpy.types.TextCurve.character_count = bpy.props.IntProperty(
  104.       name="character_count",update=update_func, min=0, options={'ANIMATABLE'})
  105.     bpy.types.TextCurve.backup_text = bpy.props.StringProperty(
  106.       name="backup_text")
  107.     bpy.types.TextCurve.use_animated_text = bpy.props.BoolProperty(
  108.       name="use_animated_text", default=False)
  109.     bpy.types.TextCurve.source_text = bpy.props.StringProperty(
  110.       name="source_text")
  111.     # register the module:
  112.     bpy.utils.register_module(__name__)
  113.     # add the frame change handler
  114.     bpy.app.handlers.frame_change_post.append(typewriter_text_update_frame)
  115.  
  116.  
  117. def unregister():
  118.     '''
  119.    addon unregistration function
  120.    '''
  121.     # remove the frame change handler
  122.     bpy.app.handlers.frame_change_post.remove(typewriter_text_update_frame)
  123.     # remove the properties
  124.     # XXX but how???
  125.     # remove the panel
  126.     bpy.utils.unregister_module(__name__)
  127.  
  128. if __name__ == "__main__":
  129.     register()
  130.  
go to heaven