I am just learning blender and python and thought I would have a go at this just as a learning exercise.
ziel has obviously produced a really good solution. I juts did a simple counter to see how it would be done and learn. I then had the idea that as well as just showing the number it could be used as a line number and reference a text block.
This was quite easy to implement once I had a countdown script.
This video shows my implementation, the new text bit starts at about 1:30:
It is quite simple but allows quick and dirty subtitles. The video itself has a text overlay done using this plugin. The text is moving and scaling slowly just using standard blender anim.
The code is here and perhaps ziel can integrate in to his better counter addon. I am happy that you use the code as long as the final plugin is GPL as the OP stated it would be.
bl_info = {
"name": "Text Animation",
"author": "Stuart Marsden",
"version": (1, 0),
"blender": (2, 69, 0),
"location": "Properties > Font > Text Animation",
"description": "Lets you animate text content",
"warning": "",
"wiki_url": "",
"category": "Font"}
import bpy #needed in a script-text-window!
def set_func(self, value):
self['countVal'] = value
if self.is_timer:
if self.is_animText:
lineNum = clamp(int(value), 1, len(bpy.data.texts[self.animText].lines)) - 1
self.data.body = bpy.data.texts[self.animText].lines[lineNum].body
else:
self.data.body = "%d" % value
def get_func(self):
return self['countVal']
def set_timer(self, context):
if 'countVal' not in self:
self.countVal = 1.0
def set_textFile(self,context):
set_func(self, self.countVal)
def clamp(n, minn, maxn):
return max(min(maxn, n), minn)
class textAnimPanel(bpy.types.Panel): # panel to display new property
"""Timer Panel"""
bl_label = "Countdown Timer"
bl_idname = "FONT_PT_timer"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
# bl_context = "data"
@classmethod
def poll(cls, context):
return (context.object and context.object.type in {'FONT'} and context.curve)
def draw_header(self, context):
obj = context.object
self.layout.prop(obj, "is_timer", text="")
def draw(self, context):
obj = context.object
if obj.is_timer:
col = self.layout.column()
col.prop(obj, "countVal", text="Count Value")
col.prop(obj, "is_animText", text="Use text file for animation")
if obj.is_animText:
col.prop_search(obj, "animText", bpy.data, "texts", text="Anim Text")
col.label(text="Length of file: %d" % len(bpy.data.texts[obj.animText].lines))
def register():
bpy.utils.register_class(textAnimPanel) # register panel
bpy.types.Object.countVal = bpy.props.IntProperty(set=set_func, get=get_func)
bpy.types.Object.is_timer = bpy.props.BoolProperty(default=False, description="Make countdown timer", update=set_timer)
bpy.types.Object.is_animText = bpy.props.BoolProperty(default=False, description="Animate using Text File")
bpy.types.Object.animText = bpy.props.StringProperty(description="Text to use for animation", update=set_textFile)
def unregister():
bpy.utils.unregister_class(textAnimPanel)
if __name__ == "__main__":
register()