How can an Addon know current Scene frame & act on a single object?

Hi everyone,

I’m an old LightWaver and had written a lot of scripts for that platform, (some of which are still being sold on Liberty3D).

I’ve moved over to Blender and have been amazed at how powerful it is.

Problem is I’m lost where it comes to animation-based Addon development. Ive gone through some beginning Addon tutorials - most of which seem to be more based on modeling.

What I’m trying to do is to create an Addon that will read a text file that contains subtitles, and the times each block of text appears and disappears.

In all my searching, I’ve not yet even been able to find reference as to how an Addon can be “added” to a single object (a Text object, for example,) and how that Addon can know the current scene time. :confused:

I’m lost. :frowning:

bpy.context.scene.frame_current will return the current frame of the active scene. (read only)

To my knowledge, you can’t add any scripting to an object per se, but you can add a handler that will run code you insert whenever an event is triggered (like a frame change)

With this you can define a function that you want to operate on each frame:

def subtitle(scene):
if scene.frame_current in subtitlearray:
#do code!

Then you can attach this code to a handler:

And it will now execute this code before displaying every frame.

Hope that points you in a helpful direction!

Thanks so much for the help! That’s much farther than I’d been able to discover looking through scripts and doing tutorials!

So… trying to grasp the concept of not being able to attach an Addon to a specific object, (like adding a plugin/script to an Object’s motion handler in LightWave,) … it seems like I’d create an Addon that adds functionality to all Text Objects… that then has a bool that the user must check in order for it to be active on that particular Text Object in that Scene?

Thanks again for pointing me in good directions!

I would create a function that checks through your subtitle data to see what subtitle should be displayed. then pass that data to a single text object in your scene (bpy.context.scene.objects[‘my_text_object’].data.body = ‘subtitle text’)

Best of Luck!

Awesome! I was wondering how to access the content of a Text Object! Thank you again, so very much!

(Can’t wait 'till next week when I’ll hopefully have time to roll up my sleeves and do some coding! I’ll let you know how it goes! :smiley: )